Skip to content

Commit e95b327

Browse files
Refactor test method names in wasm tests for improved consistency and clarity of intent.
1 parent eebaff2 commit e95b327

File tree

4 files changed

+39
-37
lines changed

4 files changed

+39
-37
lines changed

bot-api/wasm/src/wasmJsTest/kotlin/dev/robocode/tankroyale/botapi/ConstantsTest.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import kotlin.test.assertTrue
77
class ConstantsTest {
88

99
@Test
10-
fun testFixedConstantsMatchJava() {
10+
fun givenDefinedConstants_whenChecked_thenValuesMatchSpec() {
1111
assertEquals(18, Constants.BOUNDING_CIRCLE_RADIUS, "BOUNDING_CIRCLE_RADIUS mismatch")
1212
assertEquals(1200, Constants.SCAN_RADIUS, "SCAN_RADIUS mismatch")
1313

@@ -25,7 +25,7 @@ class ConstantsTest {
2525
}
2626

2727
@Test
28-
fun testComputedConstantsMatchFormulas() {
28+
fun givenComputedConstants_whenEvaluated_thenMatchFormulasAndSanityChecks() {
2929
val expectedMinBulletSpeed = 20 - 3 * Constants.MAX_FIREPOWER
3030
val expectedMaxBulletSpeed = 20 - 3 * Constants.MIN_FIREPOWER
3131

bot-api/wasm/src/wasmJsTest/kotlin/dev/robocode/tankroyale/botapi/graphics/ColorTest.kt

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import kotlin.test.assertTrue
88
class ColorTest {
99

1010
@Test
11-
fun testFromRgba_singleParameter() {
11+
fun givenRgbaInt_whenFromRgba_thenChannelsAndRoundtripMatch() {
1212
// Test creation from a single RGBA integer
1313
val rgbaValue = 0x112233FF // Red: 17, Green: 34, Blue: 51, Alpha: 255
1414
val color = Color.fromRgba(rgbaValue)
@@ -21,7 +21,7 @@ class ColorTest {
2121
}
2222

2323
@Test
24-
fun testFromRgba_rgbParameters() {
24+
fun givenRgb_whenFromRgb_thenAlphaIs255AndRoundtripRgbaMatches() {
2525
// Test creation from RGB values (alpha should be 255)
2626
val color = Color.fromRgb(100, 150, 200)
2727

@@ -33,7 +33,7 @@ class ColorTest {
3333
}
3434

3535
@Test
36-
fun testFromRgba_rgbaParameters() {
36+
fun givenRgbaComponents_whenFromRgba_thenChannelsAndRoundtripMatch() {
3737
// Test creation from RGBA values
3838
val color = Color.fromRgba(64, 32, 16, 128)
3939

@@ -45,7 +45,7 @@ class ColorTest {
4545
}
4646

4747
@Test
48-
fun testFromRgba_baseColor() {
48+
fun givenBaseColorAndAlpha_whenFromRgba_thenReturnedColorHasBaseRgbAndAlpha() {
4949
// Test creation with a base color and alpha
5050
val baseColor = Color.fromRgb(255, 200, 100)
5151
val color = Color.fromRgba(baseColor, 50)
@@ -57,7 +57,7 @@ class ColorTest {
5757
}
5858

5959
@Test
60-
fun testToRgba() {
60+
fun givenRgbaInt_whenToRgba_thenReturnsSameInt() {
6161
// Create a color and test toRgba() returns the correct value
6262
val rgbaValue = 0x11223344
6363
val color = Color.fromRgba(rgbaValue)
@@ -66,7 +66,7 @@ class ColorTest {
6666
}
6767

6868
@Test
69-
fun testRgbBoundsHandling() {
69+
fun givenOutOfRangeRgba_whenFromRgba_thenChannelsAreClampedToByte() {
7070
// Test RGB values are properly bounded to 0-255
7171
val color = Color.fromRgba(300, 300, 300, 300)
7272

@@ -78,7 +78,7 @@ class ColorTest {
7878
}
7979

8080
@Test
81-
fun testPredefinedColors() {
81+
fun givenPredefinedColors_whenToRgba_thenValuesMatchAndTransparentAlphaIsZero() {
8282
// Test a few predefined colors
8383
assertEquals(0x000000FF, Color.BLACK.toRgba())
8484
assertEquals(0xFFFFFFFF.toInt(), Color.WHITE.toRgba())
@@ -91,7 +91,7 @@ class ColorTest {
9191
}
9292

9393
@Test
94-
fun testEquality() {
94+
fun givenColors_whenEqualsAndHashCode_thenBehaveAsExpected() {
9595
// Test equality of colors
9696
val color1 = Color.fromRgba(0x112233FF)
9797
val color2 = Color.fromRgba(0x112233FF)
@@ -104,7 +104,7 @@ class ColorTest {
104104
}
105105

106106
@Test
107-
fun testToString() {
107+
fun givenOpaqueAndTransparentColors_whenToString_thenFormattedStringMatches() {
108108
// Test toString() with opaque color
109109
val opaqueColor = Color.fromRgb(100, 150, 200)
110110
assertEquals("Color(r=100, g=150, b=200)", opaqueColor.toString())
@@ -115,7 +115,7 @@ class ColorTest {
115115
}
116116

117117
@Test
118-
fun testToHexColor() {
118+
fun givenOpaqueAndTransparentColors_whenToHexColor_thenHexStringMatches() {
119119
// Test toHexColor() with opaque color
120120
val opaqueColor = Color.fromRgb(17, 34, 51)
121121
assertEquals("#112233", opaqueColor.toHexColor())
@@ -128,7 +128,7 @@ class ColorTest {
128128
// --- Merged from ColorConstantsTest ---
129129

130130
@Test
131-
fun testTransparentAndOpaqueHex() {
131+
fun givenTransparentAndWhiteColors_whenToRgbaAndToHex_thenExpectedValues() {
132132
// TRANSPARENT should have alpha 0 with white RGB per Java API
133133
val transparent = Color.TRANSPARENT
134134
assertEquals(0, transparent.a)
@@ -141,7 +141,7 @@ class ColorTest {
141141
}
142142

143143
@Test
144-
fun testSomeNamedColorsMatchJava() {
144+
fun givenSelectedNamedColors_whenToRgba_thenMatchJavaValues() {
145145
// Spot-check a selection of named colors, values taken from Java API
146146
val expected = mapOf(
147147
"ALICE_BLUE" to 0xF0F8FFFF.toInt(),
@@ -169,8 +169,8 @@ class ColorTest {
169169
}
170170

171171
@Test
172-
fun testSvgGraphicsIsIGraphics() {
172+
fun givenSvgGraphics_whenCheckingType_thenIsIGraphics() {
173173
val g = SvgGraphics()
174174
assertTrue(g is IGraphics)
175175
}
176-
}
176+
}

bot-api/wasm/src/wasmJsTest/kotlin/dev/robocode/tankroyale/botapi/graphics/PointTest.kt

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import kotlin.test.assertTrue
1212
class PointTest {
1313

1414
@Test
15-
fun testConstructorAndGetters() {
15+
fun givenCoordinates_whenConstructingPoint_thenGettersReturnSameValues() {
1616
// Given
1717
val x = 10.5
1818
val y = -5.25
@@ -26,7 +26,7 @@ class PointTest {
2626
}
2727

2828
@Test
29-
fun testEquality() {
29+
fun givenPoints_whenComparingEquality_thenBehaveAsExpected() {
3030
// Given
3131
val point1 = Point(1.0, 2.0)
3232
val point2 = Point(1.0, 2.0)
@@ -41,7 +41,7 @@ class PointTest {
4141
}
4242

4343
@Test
44-
fun testEqualityWithExactValues() {
44+
fun givenSlightDifferences_whenComparingPoints_thenNotEqualWithExactComparison() {
4545
// Given - Note: Since we now use exact equality, small differences will make points unequal
4646
val point1 = Point(1.0, 2.0)
4747
val point2 = Point(1.0, 2.0) // Exactly the same values
@@ -55,7 +55,7 @@ class PointTest {
5555
}
5656

5757
@Test
58-
fun testHashCode() {
58+
fun givenEqualPoints_whenHashCode_thenSameHashCode() {
5959
// Given
6060
val point1 = Point(1.0, 2.0)
6161
val point2 = Point(1.0, 2.0)
@@ -65,7 +65,7 @@ class PointTest {
6565
}
6666

6767
@Test
68-
fun testToString() {
68+
fun givenPoint_whenToString_thenIncludesXAndYCoordinates() {
6969
// Given
7070
val point = Point(1.0, 2.0)
7171

@@ -78,11 +78,12 @@ class PointTest {
7878
}
7979

8080
@Test
81-
fun testReflexiveEquality() {
81+
fun givenPoint_whenCheckingReflexiveEquality_thenEqualToItself() {
8282
// Given
8383
val point = Point(1.0, 2.0)
8484

8585
// Then
8686
assertEquals(point, point, "A point should be equal to itself")
8787
}
8888
}
89+

bot-api/wasm/src/wasmJsTest/kotlin/dev/robocode/tankroyale/botapi/graphics/SvgGraphicsTest.kt

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ class SvgGraphicsTest {
1414
Regex(Regex.escape(token)).findAll(text).count()
1515

1616
@Test
17-
fun testInitialState() {
17+
fun givenNewGraphics_whenToSvg_thenContainsRootSvgAndClosed() {
1818
val graphics = SvgGraphics()
1919
val svg = graphics.toSvg()
2020
assertTrue(svg.contains("<svg xmlns=\"http://www.w3.org/2000/svg\" viewBox=\"0 0 5000 5000\">"))
2121
assertTrue(svg.trim().endsWith("</svg>"))
2222
}
2323

2424
@Test
25-
fun testDrawLine() {
25+
fun givenStrokeSet_whenDrawLine_thenLineElementWithAttributesPresent() {
2626
val g = SvgGraphics()
2727
g.setStrokeColor(Color.RED)
2828
g.setStrokeWidth(2.0)
@@ -39,7 +39,7 @@ class SvgGraphicsTest {
3939
}
4040

4141
@Test
42-
fun testDrawRectangle() {
42+
fun givenStrokeSet_whenDrawRectangle_thenRectElementWithAttributesPresent() {
4343
val g = SvgGraphics()
4444
g.setStrokeColor(Color.BLUE)
4545
g.setStrokeWidth(3.0)
@@ -57,7 +57,7 @@ class SvgGraphicsTest {
5757
}
5858

5959
@Test
60-
fun testFillRectangle() {
60+
fun givenFillAndStrokeSet_whenFillRectangle_thenRectElementWithAttributesPresent() {
6161
val g = SvgGraphics()
6262
g.setFillColor(Color.GREEN)
6363
g.setStrokeColor(Color.RED)
@@ -72,7 +72,7 @@ class SvgGraphicsTest {
7272
}
7373

7474
@Test
75-
fun testDrawCircle() {
75+
fun givenStrokeSet_whenDrawCircle_thenCircleElementWithAttributesPresent() {
7676
val g = SvgGraphics()
7777
g.setStrokeColor(Color.PURPLE)
7878
g.setStrokeWidth(2.0)
@@ -89,7 +89,7 @@ class SvgGraphicsTest {
8989
}
9090

9191
@Test
92-
fun testFillCircle() {
92+
fun givenFillAndStrokeSet_whenFillCircle_thenCircleElementWithAttributesPresent() {
9393
val g = SvgGraphics()
9494
g.setFillColor(Color.YELLOW)
9595
g.setStrokeColor(Color.ORANGE)
@@ -102,7 +102,7 @@ class SvgGraphicsTest {
102102
}
103103

104104
@Test
105-
fun testDrawPolygon() {
105+
fun givenStrokeSet_whenDrawPolygon_thenPolygonElementWithAttributesPresent() {
106106
val g = SvgGraphics()
107107
g.setStrokeColor(Color.BLACK)
108108
g.setStrokeWidth(2.0)
@@ -118,7 +118,7 @@ class SvgGraphicsTest {
118118
}
119119

120120
@Test
121-
fun testFillPolygon() {
121+
fun givenFillAndStrokeSet_whenFillPolygon_thenPolygonElementWithAttributesPresent() {
122122
val g = SvgGraphics()
123123
g.setFillColor(Color.BLUE)
124124
g.setStrokeColor(Color.BLACK)
@@ -132,7 +132,7 @@ class SvgGraphicsTest {
132132
}
133133

134134
@Test
135-
fun testPolygonWithTooFewPoints() {
135+
fun givenTooFewPoints_whenDrawOrFillPolygon_thenNoPolygonIsAdded() {
136136
val g = SvgGraphics()
137137
val pts = listOf(Point(10.0, 10.0), Point(50.0, 10.0))
138138
g.drawPolygon(pts)
@@ -143,7 +143,7 @@ class SvgGraphicsTest {
143143
}
144144

145145
@Test
146-
fun testDrawText() {
146+
fun givenStrokeAndFontSet_whenDrawText_thenTextElementWithAttributesPresent() {
147147
val g = SvgGraphics()
148148
g.setStrokeColor(Color.BLUE)
149149
g.setFont("Verdana", 24.0)
@@ -160,7 +160,7 @@ class SvgGraphicsTest {
160160
}
161161

162162
@Test
163-
fun testMultipleElements() {
163+
fun givenVariousElementsDrawn_whenToSvg_thenCountsMatch() {
164164
val g = SvgGraphics()
165165
g.setStrokeColor(Color.RED)
166166
g.drawLine(10.0, 10.0, 20.0, 20.0)
@@ -176,7 +176,7 @@ class SvgGraphicsTest {
176176
}
177177

178178
@Test
179-
fun testClear() {
179+
fun givenGraphicsWithElements_whenClear_thenElementsAreRemovedFromSvg() {
180180
val g = SvgGraphics()
181181
g.setStrokeColor(Color.RED)
182182
g.drawLine(10.0, 10.0, 20.0, 20.0)
@@ -193,7 +193,7 @@ class SvgGraphicsTest {
193193
}
194194

195195
@Test
196-
fun testDefaultStrokeValues() {
196+
fun givenNoStrokeSet_whenDrawShapes_thenDefaultBlackStrokeAndWidth1Used() {
197197
val g = SvgGraphics()
198198
g.drawRectangle(10.0, 20.0, 100.0, 50.0)
199199
var svg = g.toSvg()
@@ -208,7 +208,7 @@ class SvgGraphicsTest {
208208
}
209209

210210
@Test
211-
fun testToSvgFormatting() {
211+
fun givenLineDrawn_whenToSvg_thenContainsRootSvgAndClosed() {
212212
val g = SvgGraphics()
213213
g.drawLine(10.0, 10.0, 20.0, 20.0)
214214
val svg = g.toSvg().trim()
@@ -217,7 +217,7 @@ class SvgGraphicsTest {
217217
}
218218

219219
@Test
220-
fun testNumberFormatting() {
220+
fun givenPreciseNumbers_whenToSvg_thenFormattedToThreeDecimals() {
221221
val g = SvgGraphics()
222222
g.drawLine(10.123, 20.456, 30.789, 40.987)
223223
var svg = g.toSvg()
@@ -235,3 +235,4 @@ class SvgGraphicsTest {
235235
assertTrue(svg.contains("y2=\"40.988\" "))
236236
}
237237
}
238+

0 commit comments

Comments
 (0)