Skip to content

Commit 9c45ef7

Browse files
authored
Merge pull request #4 from skainet-dev/codex/write-kmp-tests-for-shape-class
Add tests for Shape class
2 parents 982b697 + d18db6c commit 9c45ef7

1 file changed

Lines changed: 35 additions & 4 deletions

File tree

core/src/commonTest/kotlin/sk/ai/net/ShapeTest.kt

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,43 @@ package sk.ai.net
22

33
import kotlin.test.Test
44
import kotlin.test.assertEquals
5+
import kotlin.test.assertFalse
6+
import kotlin.test.assertContentEquals
57

68
class ShapeTest {
79

810
@Test
9-
fun `test scalar`() {
10-
val shape = Shape(0)
11-
assertEquals(shape, Shape(1, 2))
11+
fun volumeIsProductOfDimensions() {
12+
val shape = Shape(2, 3, 4)
13+
assertEquals(24, shape.volume)
1214
}
13-
}
15+
16+
@Test
17+
fun rankIsNumberOfDimensions() {
18+
val shape = Shape(2, 3)
19+
assertEquals(2, shape.rank)
20+
}
21+
22+
@Test
23+
fun equalityChecksAllDimensions() {
24+
val shape1 = Shape(2, 3)
25+
val shape2 = Shape(2, 3)
26+
val shape3 = Shape(3, 2)
27+
assertEquals(shape1, shape2)
28+
assertFalse(shape1 == shape3)
29+
}
30+
31+
@Test
32+
fun constructorCopiesDimensions() {
33+
val dims = intArrayOf(2, 3)
34+
val shape = Shape(*dims)
35+
dims[0] = 5
36+
assertContentEquals(intArrayOf(2, 3), shape.dimensions)
37+
}
38+
39+
@Test
40+
fun toStringContainsSizeInformation() {
41+
val shape = Shape(2, 3)
42+
assertEquals("Shape: Dimensions = [2 x 3], Size (Volume) = 6", shape.toString())
43+
}
44+
}

0 commit comments

Comments
 (0)