@@ -33,71 +33,75 @@ class ForLoopTest {
33
33
forLoopTest.clean()
34
34
}
35
35
36
+ // givenXXX_whenYYY_thenZZZ or whenXXX_thenYYY
37
+
36
38
@ Test
37
- def iterateRangeToTest (): Unit = {
39
+ def gevenInclusiveRange_whenForLoop_thenIterateOverEachElement (): Unit = {
38
40
forLoopTest.iterateRangeTo(rangeTo)
39
41
val expected = Seq (1 , 2 , 3 )
40
42
assertEquals(expected, forLoopTest.sideEffectResult)
41
43
}
42
44
43
45
@ Test
44
- def iterateRangeUntilTest (): Unit = {
46
+ def gevenExclusiveRange_whenForLoop_thenIterateOverEachElement (): Unit = {
45
47
forLoopTest.iterateRangeUntil(rangeUntil)
46
48
val expected = Seq (1 , 2 )
47
49
assertEquals(expected, forLoopTest.sideEffectResult)
48
50
}
49
51
50
52
@ Test
51
- def multipleGeneratorsTest (): Unit = {
53
+ def gevenExclusiveAndInclusiveRange_whenForLoopWithMltipleGenerators_thenCartesianProduct (): Unit = {
52
54
forLoopTest.multipleGenerators(rangeTo, rangeUntil)
53
55
val expected = Seq (" 1, 1" , " 1, 2" , " 2, 1" , " 2, 2" , " 3, 1" , " 3, 2" )
54
56
assertEquals(expected, forLoopTest.sideEffectResult)
55
57
}
56
58
57
59
@ Test
58
- def iterateCollectionTest (): Unit = {
60
+ def gevenCollection_whenForLoop_thenIterateOverEachElement (): Unit = {
59
61
forLoopTest.iterateCollection(colors)
60
62
val expected = Seq (" R" , " G" , " B" )
61
63
assertEquals(expected, forLoopTest.sideEffectResult)
62
64
}
63
65
64
66
@ Test
65
- def iterateCollectionWithMultipleGeneratorsTest (): Unit = {
67
+ def gevenCollection_whenForLoopWithMltipleGenerators_thenAllPossibleCombinations (): Unit = {
66
68
forLoopTest.iterateCollectionWithMultipleGenerators(colors)
67
- val expected = List (" RRR " , " RRG " , " RRB " , " RGR " , " RGG " , " RGB " , " RBR " , " RBG " , " RBB " , " GRR " , " GRG " , " GRB " , " GGR " , " GGG " , " GGB " , " GBR " , " GBG " , " GBB " , " BRR " , " BRG " , " BRB " , " BGR " , " BGG " , " BGB " , " BBR " , " BBG " , " BBB " )
69
+ val expected = List (" RRR " , " RRG " , " RRB " , " RGR " , " RGG " , " RGB " , " RBR " , " RBG " , " RBB " ,
70
+ " GRR " , " GRG " , " GRB " , " GGR " , " GGG " , " GGB " , " GBR " , " GBG " , " GBB " ,
71
+ " BRR " , " BRG " , " BRB " , " BGR " , " BGG " , " BGB " , " BBR " , " BBG " , " BBB " )
68
72
assertEquals(expected, forLoopTest.sideEffectResult)
69
73
}
70
74
71
75
@ Test
72
- def iterateCollectionsWithGuardsTest (): Unit = {
76
+ def gevenCollection_whenForLoopWithMltipleGeneratorsAndGuards_thenUniqueLettersCombinations (): Unit = {
73
77
forLoopTest.iterateCollectionsWithGuards(colors)
74
78
val expected = List (" RGB " , " RBG " , " GRB " , " GBR " , " BRG " , " BGR " )
75
79
assertEquals(expected, forLoopTest.sideEffectResult)
76
80
}
77
81
78
82
@ Test
79
- def iterateMapTest (): Unit = {
83
+ def gevenMap_whenForLoop_thenCollectionOfStrings (): Unit = {
80
84
forLoopTest.iterateMap(map)
81
85
val expected = List (" R is for Red" , " G is for Green" , " B is for Blue" )
82
86
assertEquals(expected, forLoopTest.sideEffectResult)
83
87
}
84
88
85
89
@ Test
86
- def iterateMapMultipleGeneratorsTest (): Unit = {
90
+ def gevenMap_whenForLoopWithMltipleGenerators_thenAllCombinationsOfKeyAndValueList (): Unit = {
87
91
forLoopTest.iterateMapMultipleGenerators(deck)
88
92
val expected = List (" A of ♣" , " K of ♣" , " Q of ♣" , " J of ♦" , " 10 of ♦" , " 9 of ♥" , " 8 of ♥" , " 7 of ♥" , " A of ♠" , " K of ♠" , " J of ♠" , " 6 of ♠" )
89
93
assertEquals(expected, forLoopTest.sideEffectResult)
90
94
}
91
95
92
96
@ Test
93
- def pureIterationTest (): Unit = {
97
+ def gevenCollection_whenForComprehension_thenReturnedCollectionOfStrings (): Unit = {
94
98
val result = forLoopTest.pureIteration(numbers)
95
99
val expected = List (" 1 + 1 = 2" , " 2 + 2 = 4" , " 3 + 3 = 6" )
96
100
assertEquals(expected, result)
97
101
}
98
102
99
103
@ Test
100
- def forComprehensionWithOptionalsTest (): Unit = {
104
+ def gevenOptionals_whenForComprehensionOrMap_thenReturnedOptional (): Unit = {
101
105
102
106
val resultFor = forLoopTest.forComprehensionWithOptionals(someIntValue, someStringValue)
103
107
val resultMap = forLoopTest.mapOptionals(someIntValue, someStringValue)
0 commit comments