Skip to content

Commit c20a760

Browse files
committed
Change to table tests
1 parent 88bd9ac commit c20a760

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

puan/ruleset_test.go

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -374,74 +374,79 @@ func Test_validateVariables_givenUniquePeriod_shouldReturnError(t *testing.T) {
374374
assert.Error(t, err)
375375
}
376376

377-
func Test_RuleSet_isValidTime_givenNilTimestamp_shouldReturnTrue(t *testing.T) {
378-
ruleset := Ruleset{}
379-
380-
got := ruleset.isValidTime(nil)
381-
382-
assert.True(t, got)
383-
}
384-
385-
func Test_RuleSet_isValidTime_givenNoTimeboundVariablesInRuleset_shouldReturnTrue(t *testing.T) {
386-
ruleset := Ruleset{}
387-
timestamp := fake.New[time.Time]()
388-
389-
got := ruleset.isValidTime(&timestamp)
390-
391-
assert.True(t, got)
392-
}
393-
394-
func Test_RuleSet_isValidTime_givenTimeboundVariablesEndingAfterTimestamp_shouldReturnTrue(t *testing.T) {
377+
func Test_RuleSet_isValidTime(t *testing.T) {
395378
timestamp := fake.New[time.Time]()
396-
afterTimestamp := timestamp.Add(1 * time.Hour)
397-
timeboundVariables := TimeBoundVariable{
398-
period: Period{
399-
to: afterTimestamp,
400-
},
379+
before := timestamp.Add(-1 * time.Hour)
380+
after := timestamp.Add(1 * time.Hour)
381+
382+
type testCase struct {
383+
name string
384+
ruleset Ruleset
385+
timestamp *time.Time
386+
want bool
401387
}
402-
ruleset := Ruleset{
403-
periodVariables: TimeBoundVariables{
404-
timeboundVariables,
405-
},
406-
}
407-
408-
got := ruleset.isValidTime(&timestamp)
409388

410-
assert.True(t, got)
411-
}
412-
413-
func Test_RuleSet_isValidTime_givenTimeboundVariablesEndingAtTimestamp_shouldReturnTrue(t *testing.T) {
414-
timestamp := fake.New[time.Time]()
415-
timeboundVariables := TimeBoundVariable{
416-
period: Period{
417-
to: timestamp,
389+
cases := []testCase{
390+
{
391+
name: "given nil timestamp, should return true",
392+
ruleset: Ruleset{},
393+
timestamp: nil,
394+
want: true,
418395
},
419-
}
420-
ruleset := Ruleset{
421-
periodVariables: TimeBoundVariables{
422-
timeboundVariables,
396+
{
397+
name: "given no timebound variables in ruleset, should return true",
398+
ruleset: Ruleset{},
399+
timestamp: &timestamp,
400+
want: true,
423401
},
424-
}
425-
426-
got := ruleset.isValidTime(&timestamp)
427-
428-
assert.True(t, got)
429-
}
430-
func Test_RuleSet_isValidTime_givenOnlyTimeboundVariablesBeforeTimestamp_shouldReturnFalse(t *testing.T) {
431-
timestamp := fake.New[time.Time]()
432-
beforeTimestamp := timestamp.Add(-1 * time.Hour)
433-
timeboundVariables := TimeBoundVariable{
434-
period: Period{
435-
to: beforeTimestamp,
402+
{
403+
name: "given timebound variables ending after timestamp, should return true",
404+
ruleset: Ruleset{
405+
periodVariables: TimeBoundVariables{
406+
{
407+
period: Period{
408+
to: after,
409+
},
410+
},
411+
},
412+
},
413+
timestamp: &timestamp,
414+
want: true,
436415
},
437-
}
438-
ruleset := Ruleset{
439-
periodVariables: TimeBoundVariables{
440-
timeboundVariables,
416+
{
417+
name: "given timebound variables ending at timestamp, should return true",
418+
ruleset: Ruleset{
419+
periodVariables: TimeBoundVariables{
420+
{
421+
period: Period{
422+
to: timestamp,
423+
},
424+
},
425+
},
426+
},
427+
timestamp: &timestamp,
428+
want: true,
429+
},
430+
{
431+
name: "given only timebound variables before timestamp, should return false",
432+
ruleset: Ruleset{
433+
periodVariables: TimeBoundVariables{
434+
{
435+
period: Period{
436+
to: before,
437+
},
438+
},
439+
},
440+
},
441+
timestamp: &timestamp,
442+
want: false,
441443
},
442444
}
443445

444-
got := ruleset.isValidTime(&timestamp)
445-
446-
assert.False(t, got)
446+
for _, tt := range cases {
447+
t.Run(tt.name, func(t *testing.T) {
448+
got := tt.ruleset.isValidTime(tt.timestamp)
449+
assert.Equal(t, tt.want, got)
450+
})
451+
}
447452
}

0 commit comments

Comments
 (0)