Added some documentation for this folder; Updated the tests up to 2020 (testTimes.lua) to the new interface for summer and winter time calculation
This commit is contained in:
		
							
								
								
									
										25
									
								
								unit/ReadMe.md
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								unit/ReadMe.md
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,25 @@
 | 
			
		||||
# Unit tests for the timecore module in the parent folder
 | 
			
		||||
## Test generation
 | 
			
		||||
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.
 | 
			
		||||
 | 
			
		||||
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
 | 
			
		||||
 | 
			
		||||
## UnixTimestamp to local time convertion
 | 
			
		||||
These tests combins both chaptes above.
 | 
			
		||||
 | 
			
		||||
## Test execution
 | 
			
		||||
All tests were executed on Linux with LUA version 5.1.5
 | 
			
		||||
 | 
			
		||||
The tests can be reproduced with the following commands:
 | 
			
		||||
 | 
			
		||||
```
 | 
			
		||||
$ lua testTimesMarchOctober.lua
 | 
			
		||||
$ lua testTimes.lua
 | 
			
		||||
```
 | 
			
		||||
@@ -4,7 +4,19 @@
 | 
			
		||||
#date -d '2007-011-01 17:30:24' '+%:z'
 | 
			
		||||
#+01:00
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
HEAD=timetest_head.template
 | 
			
		||||
TAIL=timetest_tail.template
 | 
			
		||||
# 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 ..."
 | 
			
		||||
cat $HEAD > $OUTPUT
 | 
			
		||||
 | 
			
		||||
for year in {2017..2020}; do
 | 
			
		||||
 echo "For $year ..."
 | 
			
		||||
 for month in {1..12}; do
 | 
			
		||||
  for day in {1..31}; do
 | 
			
		||||
    hour=$((RANDOM%24))
 | 
			
		||||
@@ -13,16 +25,23 @@ for year in {2017..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
 | 
			
		||||
     # Result of date looks like +01:00
 | 
			
		||||
     # Grep extracts the hour, then remove the plus in front and at the end remove leading zeros
 | 
			
		||||
     offset=$(date -d "$timestmp" '+%:z' | grep -o "+[0-9]*" | sed 's/+//' | sed 's/^0//')
 | 
			
		||||
     dayofweek=$(date -d "$timestmp" '+%u')
 | 
			
		||||
     # Generate the lua test command, like: checkTime(2015, 1, 1, 10, 11, 12, 0, 1)
 | 
			
		||||
     echo "checkTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $offset)"
 | 
			
		||||
     echo "checkTime($year, $month, $day, $hour, $minutes, $seconds, $dayofweek, $offset)" >> $OUTPUT
 | 
			
		||||
    fi
 | 
			
		||||
  done
 | 
			
		||||
 done
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
cat $TAIL >> $OUTPUT
 | 
			
		||||
 | 
			
		||||
echo "---------------------------"
 | 
			
		||||
echo "Usage:"
 | 
			
		||||
echo "Call >lua $OUTPUT< in the terminal to execute the test"
 | 
			
		||||
 | 
			
		||||
exit 0
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										1510
									
								
								unit/testTimes.lua
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										1510
									
								
								unit/testTimes.lua
									
									
									
									
									
										Normal file
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
							
								
								
									
										1879
									
								
								unit/timetest.lua
									
									
									
									
									
								
							
							
						
						
									
										1879
									
								
								unit/timetest.lua
									
									
									
									
									
								
							
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							
		Reference in New Issue
	
	Block a user