This repository has been archived by the owner on Jan 20, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
suncal_test.go
51 lines (40 loc) · 1.66 KB
/
suncal_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package suncal
import (
"fmt"
"testing"
"time"
)
func TestDefault(t *testing.T) {
coords := GeoCoordinates{50.0, 10.0}
fmt.Printf("Coordinates %s\n", coords)
rise := time.Date(2005, 9, 30, 7, 18, 0, 0, time.FixedZone("CET", 7200))
set := time.Date(2005, 9, 30, 19, 00, 0, 0, time.FixedZone("CET", 7200))
date := time.Date(2005, 9, 30, 0, 0, 0, 0, time.FixedZone("CET", 7200))
sun := SunCal(coords, date)
if !sun.Rise.Equal(rise) {
t.Errorf("SunCal failed for rise, got %s, want %s", sun.Rise.String(), rise.String())
}
if !sun.Set.Equal(set) {
t.Errorf("SunCal failed for dawn, got %v, want %q", sun.Set.String(), set.String())
}
fmt.Printf("Date %d-%02d-%02d\n", date.Year(), date.Month(), date.Day())
fmt.Printf("Rise %02d:%02d\n", sun.Rise.Hour(), sun.Rise.Minute())
fmt.Printf("Set %02d:%02d\n", sun.Set.Hour(), sun.Set.Minute())
}
func TestMunich(t *testing.T) {
coords := GeoCoordinates{48.137222, 11.575556} // Munich, Germany
fmt.Printf("Coordinates %s\n", coords)
rise := time.Date(2015, 11, 18, 7, 24, 0, 0, time.FixedZone("CET", 3600))
set := time.Date(2015, 11, 18, 16, 32, 0, 0, time.FixedZone("CET", 3600))
date := time.Date(2015, 11, 18, 0, 0, 0, 0, time.FixedZone("CET", 3600))
sun := SunCal(coords, date)
if !sun.Rise.Equal(rise) {
t.Errorf("SunCal failed for rise, got %s, want %s", sun.Rise.String(), rise.String())
}
if !sun.Set.Equal(set) {
t.Errorf("SunCal failed for dawn, got %v, want %q", sun.Set.String(), set.String())
}
fmt.Printf("Date %d-%02d-%02d\n", date.Year(), date.Month(), date.Day())
fmt.Printf("Rise %02d:%02d\n", sun.Rise.Hour(), sun.Rise.Minute())
fmt.Printf("Set %02d:%02d\n", sun.Set.Hour(), sun.Set.Minute())
}