Successfully tested unixtimestamp to UTC time convertion

This commit is contained in:
ollo 2016-05-15 16:21:16 +02:00
parent 34e3f1a78e
commit b441e62a4d
3 changed files with 1892 additions and 1869 deletions

View File

@ -4,12 +4,14 @@ The tests were generated using the date command provided with linux.
### Summer- Winter- Time calculation
The file `testTimesMarchOctober.lua` tests all days in March and October until the year 2100.
It was generated with `generateTimesMarchOctober.sh`. As the minutes and seconds are generated randomly a new testscript can show new erros.
It was generated with `generateTimesMarchOctober.sh`. As the minutes and seconds are generated randomly a new testscript can help to show new erros.
The file `testTimes.lua` tests all days from this year up to the year 2020.
It was generated with `testTimes.lua`.
### UnixTimestamp to UTC convertion
The file `testUnixtimes.lua` tests the convertion of an unixtimestamp (Second since 1970) to year, month, day, hour, minute, second and dayOfWeek.
It was generated with `generateUnixtimes.sh`. As the hour, minutes and seconds are generated randomly a new testscript can help to show new errors.
## UnixTimestamp to local time convertion
These tests combins both chaptes above.
@ -22,4 +24,5 @@ The tests can be reproduced with the following commands:
```
$ lua testTimesMarchOctober.lua
$ lua testTimes.lua
$ lua testUnixtimes.lua
```

View File

@ -7,14 +7,23 @@
#4
# Usage:
# Call this script and write the output of stdout into a file.
# e.g.: ./generateUnixtime.sh > unixtimetest.lua
# Call this script and generate a new testUnixtime.lua
# Run the test afterwards like the following:
# $ lua testUnixtime.lua
# remove the tailing "./" and the extension of this script
OUTPUT="$(echo "$0" | sed 's;^./;;' | cut -d'.' -f1).lua"
#rename OUTPUT from generate to test
OUTPUT="$(echo "$OUTPUT" | sed 's;generate;test;')"
echo "Generating $OUTPUT ..."
# Generate the header
cat << EOF
cat << EOF > $OUTPUT
dofile("../timecore.lua")
function checkUnixTime(resultYear, resultMonth, resultDay, resultHour, resultMinute, resultSecond, resultDow, unixtime)
year, month, day, hour, minute, second, dow = gettime(unixtime)
year, month, day, hour, minute, second, dow = getUTCtime(unixtime)
if not (year == resultYear and resultMonth == month and day == resultDay and hour == resultHour and minute == resultMinute and second == resultSecond and dow == resultDow) then
print(resultYear .. "-" .. resultMonth .. "-" .. resultDay .. " " .. resultHour .. ":" .. resultMinute .. ":" .. resultSecond .. " day of week : " .. resultDow .. " not extracted from " .. unixtime)
@ -38,15 +47,24 @@ for year in {2016..2020}; do
timestmp="$year-$month-$day $hour:$minutes:$seconds"
date -d "$timestmp" "+%F %T" >> /dev/null
if [ $? -ne 0 ]; then
echo "--Time $timestmp is not valid"
echo "--Time $timestmp is not valid" >> $OUTPUT
else
unixtime=$(date -u -d "$timestmp" '+%s')
dayofweek=$(date -u -d "$timestmp" '+%w')
# Generate the lua test command, like: checkTime(2015, 1, 1, 10, 11, 12, 0, 1)
echo "checkUnixTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $unixtime)"
echo "checkUnixTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $unixtime)" >> $OUTPUT
fi
done
done
done
# Generate the footer
cat << EOF >> $OUTPUT
print "Finished with all tests"
os.exit(0)
EOF
echo "---------------------------"
echo "Usage:"
echo "Call >lua $OUTPUT< in the terminal to execute the test"
exit 0

File diff suppressed because it is too large Load Diff