더북(TheBook)
fun randomNatural() = Random.nextInt(from = 1, until = 100_000_000) 
 
@Test
fun `zero identity`() {        
    repeat(100) {              
        val x = randomNatural()
        expectThat(x + 0).isEqualTo(x)
    }
}
 
@Test
fun `commutative property`() { 
    repeat(100) {
        val x = randomNatural()
        val y = randomNatural()
        expectThat(x + y).isEqualTo(y + x)
    }
}
 
@Test
fun `associative property`() { 
        repeat(100) {
            val x = randomNatural()
            val y = randomNatural()
            val z = randomNatural()
            expect {           
                that((x + y) + z).isEqualTo(x + (y + z))
                that((y + z) + x).isEqualTo(y + (z + x))
                that((z + x) + y).isEqualTo(z + (x + y))
            }
        }
    }
신간 소식 구독하기
뉴스레터에 가입하시고 이메일로 신간 소식을 받아 보세요.