You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
116 lines
2.8 KiB
116 lines
2.8 KiB
import org.scalatest.funsuite.AnyFunSuite
|
|
import nova.monadic_sfx.util.MutHistory
|
|
import com.typesafe.scalalogging.LazyLogging
|
|
class MutHistoryTest extends AnyFunSuite with LazyLogging {
|
|
val h = new MutHistory(0)
|
|
|
|
test("init") {
|
|
assert(h.values == Vector(0))
|
|
assert(h.sp == 0)
|
|
assert(h.current == 0)
|
|
}
|
|
test("push 1") {
|
|
h.push(1)
|
|
// logger.debug(mutHistory.ints.toString)
|
|
assert(h.values == Vector(0, 1))
|
|
assert(h.values.length - 1 == h.sp)
|
|
assert(h.current == 1)
|
|
}
|
|
test("push 2") {
|
|
h.push(2)
|
|
// logger.debug(mutHistory.ints.toString)
|
|
assert(h.values == Vector(0, 1, 2))
|
|
assert(h.values.length - 1 == h.sp)
|
|
assert(h.current == 2)
|
|
}
|
|
test("first forward") {
|
|
// logger.debug(mutHistory.ints.toString)
|
|
// logger.debug(mutHistory.sp.toString)
|
|
h.forward()
|
|
assert(h.values == Vector(0, 1, 2))
|
|
assert(h.sp == 2)
|
|
assert(h.current == 2)
|
|
}
|
|
test("second forward") {
|
|
// logger.debug(mutHistory.ints.toString)
|
|
// logger.debug(mutHistory.sp.toString)
|
|
h.forward()
|
|
assert(h.values == Vector(0, 1, 2))
|
|
assert(h.sp == 2)
|
|
assert(h.current == 2)
|
|
}
|
|
|
|
test("first backward") {
|
|
h.backward()
|
|
assert(h.values == Vector(0, 1, 2))
|
|
assert(h.sp == 1)
|
|
assert(h.current == 1)
|
|
}
|
|
test("second backward") {
|
|
h.backward()
|
|
assert(h.values == Vector(0, 1, 2))
|
|
assert(h.sp == 0)
|
|
assert(h.current == 0)
|
|
}
|
|
test("third backward") {
|
|
h.backward()
|
|
assert(h.values == Vector(0, 1, 2))
|
|
assert(h.sp == 0)
|
|
assert(h.current == 0)
|
|
}
|
|
test("push 3") {
|
|
h.push(3)
|
|
assert(h.sp == 0)
|
|
assert(h.values == Vector(3))
|
|
assert(h.current == 3)
|
|
}
|
|
test("fourth backward") {
|
|
h.backward()
|
|
assert(h.values == Vector(3))
|
|
assert(h.sp == 0)
|
|
assert(h.current == 3)
|
|
}
|
|
test("lastly") {
|
|
h.push(4)
|
|
h.push(5)
|
|
h.push(6)
|
|
h.push(7)
|
|
h.push(8)
|
|
assert(h.values == Vector(3, 4, 5, 6, 7, 8))
|
|
assert(h.sp == 5)
|
|
assert(h.current == 8)
|
|
h.backward()
|
|
h.backward()
|
|
assert(h.current == 6)
|
|
assert(h.sp == 3)
|
|
h.push(9)
|
|
assert(h.values == Vector(3, 4, 5, 9))
|
|
assert(h.sp == 3)
|
|
assert(h.current == 9)
|
|
for (i <- 1 to 4) h.backward()
|
|
// assert(h.current == None)
|
|
// assert(h.ints == Vector.empty)
|
|
assert(h.sp == 0)
|
|
assert(h.current == 3)
|
|
h.push(1)
|
|
assert(h.current == 1)
|
|
assert(h.sp == 0)
|
|
|
|
}
|
|
}
|
|
|
|
// test("main") {
|
|
// assert(mutHistory.ints == Vector.empty)
|
|
// assert(mutHistory.sp == -1)
|
|
// mutHistory.push(1)
|
|
// assert(mutHistory.ints == Vector(1))
|
|
// assert(mutHistory.sp == 0)
|
|
// mutHistory.push(2)
|
|
// assert(mutHistory.ints == Vector(1, 2))
|
|
// assert(mutHistory.sp == 1)
|
|
// // mutHistory.forward()
|
|
// // assert(mutHistory.sp == 1)
|
|
// // mutHistory.forward()
|
|
// // assert(mutHistory.sp == 1)
|
|
// }
|
|
//
|