Skip to content

Commit

Permalink
Merge branch 'test-assignments-due'
Browse files Browse the repository at this point in the history
  • Loading branch information
lschuermann committed Sep 12, 2023
2 parents e469690 + 9ce50ad commit 4cbeec8
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 1 deletion.
6 changes: 5 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,9 @@ func main() {
fmt.Println("Hello COS316!")

assignment_due := utils.AssignmentDueToday(time.Now())
fmt.Println("Could there be an assignment due today?", assignment_due)
fmt.Printf(
"Today is a %s. Could there be an assignment due today? %t\n",
time.Now().Weekday(),
assignment_due,
)
}
30 changes: 30 additions & 0 deletions utils/assignments_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package utils

import (
"testing"
"math/rand"
"time"
)

// https://stackoverflow.com/a/43497333, CC BY-SA 3.0 @mkopriva
func randdate() time.Time {
min := time.Date(1970, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
max := time.Date(2070, 1, 0, 0, 0, 0, 0, time.UTC).Unix()
delta := max - min

sec := rand.Int63n(delta) + min
return time.Unix(sec, 0)
}

func TestAssignmentDueToday(t *testing.T) {
for i := 0; i < 1000; i++ {
// Generate a random date. If its a Wednesday,
// an assignment should be due...
date := randdate()

if (date.Weekday() == time.Wednesday) != AssignmentDueToday(date) {
t.Errorf("Assignment should be due on %s!", date);
}
}
}

0 comments on commit 4cbeec8

Please sign in to comment.