|
| 1 | +package com.baeldung.scala.listtotuple |
| 2 | + |
| 3 | + |
| 4 | +import org.scalatest.flatspec.AnyFlatSpec |
| 5 | +import org.scalatest.matchers.should.Matchers |
| 6 | +import org.scalatest.matchers.should.Matchers.shouldBe |
| 7 | + |
| 8 | +class ConvertListToTupleUnitTest extends AnyFlatSpec with Matchers { |
| 9 | + "twoElementsToTuple" should "convert list with 2 elements" in { |
| 10 | + val testList = List("Hello", "world") |
| 11 | + ConvertListToTuple.twoElementsToTuple(testList) shouldBe ("Hello", "world") |
| 12 | + } |
| 13 | + |
| 14 | + "twoElementsToTuple" should "convert list with 3 elements to Tuple3" in { |
| 15 | + val testList = List("Hello", "world", "!") |
| 16 | + ConvertListToTuple.twoElementsToTuple(testList) shouldBe ("Hello", "world") |
| 17 | + } |
| 18 | + |
| 19 | + "twoElementsToTupleUsingMatch" should "convert list with 2 elements" in { |
| 20 | + val testList = List("Hello", "world") |
| 21 | + ConvertListToTuple.twoElementsToTupleUsingMatch(testList) shouldBe ("Hello", "world") |
| 22 | + } |
| 23 | + |
| 24 | + "twoElementsToTupleUsingMatch" should "convert list with 3 elements to tuple2 ignoring extra elements" in { |
| 25 | + val testList = List("Hello", "world", "!") |
| 26 | + ConvertListToTuple.twoElementsToTupleUsingMatch(testList) shouldBe ("Hello", "world") |
| 27 | + } |
| 28 | + |
| 29 | + "twoElementsToTupleUsingMatch" should "return empty Strings for 1 element" in { |
| 30 | + val testList = List("Hello") |
| 31 | + ConvertListToTuple.twoElementsToTupleUsingMatch(testList) shouldBe ("", "") |
| 32 | + } |
| 33 | + |
| 34 | + "twoElementsToTupleUsingMatch" should "return empty Strings for Nil" in { |
| 35 | + val testList = Nil |
| 36 | + ConvertListToTuple.twoElementsToTupleUsingMatch(testList) shouldBe ("", "") |
| 37 | + } |
| 38 | + |
| 39 | + "unknownSizeToTuple" should "return empty Strings for Nil" in { |
| 40 | + val testList = Nil |
| 41 | + ConvertListToTuple.unknownSizeToTuple(testList) shouldBe ("", "") |
| 42 | + } |
| 43 | + |
| 44 | + "unknownSizeToTuple" should "convert list of 2 elements to tuple2" in { |
| 45 | + val testList = List("Hello", "world") |
| 46 | + ConvertListToTuple.unknownSizeToTuple(testList) shouldBe ("Hello", "world") |
| 47 | + } |
| 48 | + |
| 49 | + "unknownSizeToTuple" should "convert list of 3 elements to tuple3" in { |
| 50 | + val testList = List("Hello", "world", "!") |
| 51 | + ConvertListToTuple.unknownSizeToTuple(testList) shouldBe ("Hello", "world", "!") |
| 52 | + } |
| 53 | +} |
0 commit comments