Add Rect unit tests

This commit is contained in:
Shadowfacts 2019-06-22 11:06:39 -04:00
parent 27518c68df
commit 1dffc67339
Signed by: shadowfacts
GPG Key ID: 94A5AB95422746E5
2 changed files with 40 additions and 1 deletions

View File

@ -3,7 +3,7 @@ package net.shadowfacts.shadowui.geometry
/**
* @author shadowfacts
*/
class Point(val x: Double, val y: Double) {
data class Point(val x: Double, val y: Double) {
constructor(x: Int, y: Int): this(x.toDouble(), y.toDouble())

View File

@ -0,0 +1,39 @@
package net.shadowfacts.shadowui.geometry
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
/**
* @author shadowfacts
*/
class RectTest {
@Test
fun testTrailingEdges() {
val rect = Rect(25.0, 50.0, 100.0, 200.0)
assertEquals(125.0, rect.right)
assertEquals(250.0, rect.bottom)
}
@Test
fun testCenter() {
val rect = Rect(25.0, 50.0, 100.0, 200.0)
assertEquals(75.0, rect.midX)
assertEquals(150.0, rect.midY)
}
@Test
fun testPoints() {
val rect = Rect(25.0, 50.0, 100.0, 200.0)
assertEquals(Point(25.0, 50.0), rect.origin)
assertEquals(Point(75.0, 150.0), rect.center)
}
@Test
fun testSize() {
val rect = Rect(25.0, 50.0, 100.0, 200.0)
assertEquals(Size(100.0, 200.0), rect.size)
}
}