Booleans
Contents
Description
The parameter weekday is true if it is a weekday, and the parameter vacation is true if we are on vacation. We sleep in if it is not a weekday or we’re on vacation. Return true if we sleep in.
My solution
1
2
3
4
5
package scratch
func SleepIn(weekday bool, vacation bool) bool {
return !weekday || vacation
}
Tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
package scratch
import "testing"
func TestSleepIn(t *testing.T) {
tables := []struct {
weekday, vacation, result bool
}{
{false, false, true},
{true, false, false},
{false, true, true},
}
for _, table := range tables {
result := SleepIn(table.weekday, table.vacation)
if result != table.result {
t.Errorf("Expected %t, got %t", table.result, result)
}
}
}