mirror of
https://github.com/curioustorvald/Terrarum.git
synced 2026-06-11 02:54:04 +09:00
circular array is fixed and tested
This commit is contained in:
47
src/net/torvald/terrarum/tests/CircularArrayTest.kt
Normal file
47
src/net/torvald/terrarum/tests/CircularArrayTest.kt
Normal file
@@ -0,0 +1,47 @@
|
||||
import net.torvald.dataclass.CircularArray
|
||||
|
||||
/**
|
||||
* Created by minjaesong on 2019-01-09.
|
||||
*/
|
||||
class CircularArrayTest {
|
||||
|
||||
operator fun invoke() {
|
||||
val testSet = CircularArray<Int?>(5)
|
||||
val testSet2 = CircularArray<Int?>(5)
|
||||
|
||||
for (i in 1..5) {
|
||||
testSet.add(i)
|
||||
}
|
||||
|
||||
println("Metadata:")
|
||||
println(testSet)
|
||||
println("forEach():")
|
||||
testSet.forEach { print("$it ") }
|
||||
println("\nfold(0, sum):")
|
||||
println(testSet.fold(0) { acc, v -> acc + (v ?: 0) })
|
||||
println("Raw:")
|
||||
testSet.buffer.forEach { print("$it ") }
|
||||
println()
|
||||
|
||||
println()
|
||||
for (i in 1..6) {
|
||||
testSet2.add(i)
|
||||
}
|
||||
|
||||
println("Metadata:")
|
||||
println(testSet2)
|
||||
println("forEach():")
|
||||
testSet2.forEach { print("$it ") }
|
||||
println("\nfold(0, sum):")
|
||||
println(testSet2.fold(0) { acc, v -> acc + (v ?: 0) })
|
||||
println("Raw:")
|
||||
testSet2.buffer.forEach { print("$it ") }
|
||||
println()
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
fun main(args: Array<String>) {
|
||||
CircularArrayTest().invoke()
|
||||
}
|
||||
Reference in New Issue
Block a user