Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/test-assignments-due'
Browse files Browse the repository at this point in the history
  • Loading branch information
lschuermann committed Sep 12, 2023
2 parents 7220417 + d03bbab commit bbaa49d
Show file tree
Hide file tree
Showing 2 changed files with 44 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,
)
}
39 changes: 39 additions & 0 deletions utils/assignments_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
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()

t.Logf(
"Testing date %s (%s)! Assignment due today: %t",
date,
date.Weekday(),
AssignmentDueToday(date),
);

isWednesday := date.Weekday() == time.Wednesday

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

0 comments on commit bbaa49d

Please sign in to comment.