Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //test: StudentTest
- import org.scalatest.FunSuite
- import Solution._
- class StudentTest extends FunSuite {
- test("listFrom") {
- assertResult(Element(3, Element(2, Element(1, Empty())))) {
- listFrom(3)
- }
- }
- test("listFromEdge") {
- assertResult(Empty()) {
- listFrom(0)
- }
- }
- test("sumIntList") {
- assertResult(10) {
- sumIntList(Element(1, Element(2, Element(3, Element(4, Empty())))))
- }
- }
- test("sumIntListEdge") {
- assertResult(0) {
- sumIntList(Empty())
- }
- }
- test("headEdge") {
- assertThrows[NoSuchElementException] { // alternative: intercept[NoSuchElementException]
- head(Empty())
- }
- }
- test("head") {
- assertResult(1) {
- head(Element(1, Element(2, Element(3, Empty()))))
- }
- }
- test("tailEdge") {
- assertThrows[NoSuchElementException] { // alternative: intercept[NoSuchElementException]
- tail(Empty())
- }
- }
- test("tail") {
- assertResult(Element(2, Element(3, Empty()))) {
- tail(Element(1, Element(2, Element(3, Empty()))))
- }
- }
- test("Head empty") {
- intercept[NoSuchElementException] {
- head(Empty())
- }
- }
- test("Tail") {
- assertResult(Element(3, Empty())) {
- tail(Element(34, Element(3, Empty())))
- }
- }
- test("Concat more elements xs.size() > ys.size()") {
- assertResult(Element(34, Element(3, Element(6, Empty())))) {
- concat(Element(34, Element(3, Empty())), Element(6, Empty()))
- }
- }
- test("Concat more elements xs.size() < ys.size()") {
- assertResult(Element(3, Element(34, Element(6, Empty())))) {
- concat(Element(3, Empty()), Element(34, Element(6, Empty())))
- }
- }
- test("Concat more elements xs.size() == ys.size()") {
- assertResult(Element(1, Element(6, Empty()))) {
- concat(Element(1, Empty()), Element(6, Empty()))
- }
- }
- test("Concat xs Nil") {
- assertResult(Element(6, Empty())) {
- concat(Empty(), Element(6, Empty()))
- }
- }
- test("Concat ys Nil") {
- assertResult(Element(6, Empty())) {
- concat(Element(6, Empty()), Empty())
- }
- }
- test("Concat both xs & ys Nils") {
- assertResult(Empty()) {
- concat(Empty(), Empty())
- }
- }
- test("take n > size()") {
- assertResult(Element(34, Element(3, Element(6, Empty())))) {
- take(10, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- test("take n == size()") {
- assertResult(Element(34, Element(3, Element(6, Empty())))) {
- take(3, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- test("take n < size()") {
- assertResult(Element(34, Element(3, Empty()))) {
- take(2, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- test("take n == 1") {
- assertResult(Element(34, Empty())) {
- take(1, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- test("drop n == 0") {
- assertResult(Element(34, Element(3, Element(6, Empty())))) {
- drop(0, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- test("drop n == 1") {
- assertResult(Element(3, Element(6, Empty()))) {
- drop(1, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- test("drop n == size()") {
- assertResult(Empty()) {
- drop(3, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- test("drop n > size()") { // same behavior as n == size()
- assertResult(Empty()) {
- drop(4, Element(34, Element(3, Element(6, Empty()))))
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement