This repository has been archived by the owner on Dec 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 72
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
f816f63
commit 207572c
Showing
7 changed files
with
503 additions
and
2 deletions.
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
test/junit/src/test/scala/strawman/collection/ArrayOpsTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package strawman.collection | ||
|
||
import org.junit.Assert._ | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
import strawman.collection.immutable.List | ||
|
||
@RunWith(classOf[JUnit4]) | ||
class ArrayOpsTest { | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWhenInputHasSameNumberOfElements = { | ||
val array: ArrayOps[Int] = Array(1, 2, 3) | ||
val result: Array[(Int, String)] = array.zip(List("a", "b", "c")) | ||
|
||
assertArrayEquals(Array((1, "a"), (2, "b"), (3, "c")).asInstanceOf[Array[AnyRef]], result.asInstanceOf[Array[AnyRef]]) | ||
} | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWhenInputHasMoreElements = { | ||
val array: ArrayOps[Int] = Array(1, 2) | ||
val result: Array[(Int, String)] = array.zip(List("a", "b", "c")) | ||
|
||
assertArrayEquals(Array((1, "a"), (2, "b")).asInstanceOf[Array[AnyRef]], result.asInstanceOf[Array[AnyRef]]) | ||
} | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWhenInputHasLessElements = { | ||
val array: ArrayOps[Int] = Array(1, 2, 3) | ||
val result: Array[(Int, String)] = array.zip(List("a", "b")) | ||
|
||
assertArrayEquals(Array((1, "a"), (2, "b")).asInstanceOf[Array[AnyRef]], result.asInstanceOf[Array[AnyRef]]) | ||
} | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWhenInputIsEmpty = { | ||
val array: ArrayOps[Int] = Array(1, 2, 3) | ||
val result: Array[(Int, Int)] = array.zip(List.empty[Int]) | ||
|
||
assertEquals(0, result.length) | ||
} | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWithWhenInputHasSameNumberOfElements = { | ||
val result: Array[Int] = Array(1, 2, 3).zipWith(List(4, 5, 6))(_ + _) | ||
|
||
assertArrayEquals(Array(5, 7, 9), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWithWhenInputHasMoreElements = { | ||
val result: Array[Int] = Array(1, 2).zipWith(List(4, 5, 6))(_ * _) | ||
|
||
assertArrayEquals(Array(4, 10), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWithWhenInputHasLessElements = { | ||
val result: Array[Int] = Array(1, 2, 3).zipWith(List(4, 5))(_ + _) | ||
|
||
assertArrayEquals(Array(5, 7), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectOverloadedZipWithWhenInputIsEmpty = { | ||
val result: Array[Int] = Array(1, 2, 3).zipWith(List.empty[Int])(_ % _) | ||
|
||
assertEquals(0, result.length) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
122 changes: 122 additions & 0 deletions
122
test/junit/src/test/scala/strawman/collection/immutable/ImmutableArrayTest.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
package strawman.collection.immutable | ||
|
||
import org.junit.Assert._ | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.junit.runners.JUnit4 | ||
|
||
@RunWith(classOf[JUnit4]) | ||
class ImmutableArrayTest { | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsImmutableArrayAndHasSameNumberOfElements = { | ||
val result: ImmutableArray[(Int, String)] = ImmutableArray(1, 2, 3).zip(ImmutableArray("a", "b", "c")) | ||
|
||
assertEquals(ImmutableArray((1, "a"), (2, "b"), (3, "c")), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsImmutableArrayAndHasMoreElements = { | ||
val result: ImmutableArray[(Int, String)] = ImmutableArray(1, 2).zip(ImmutableArray("a", "b", "c")) | ||
|
||
assertEquals(ImmutableArray((1, "a"), (2, "b")), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsImmutableArrayAndHasLessElements = { | ||
val result: ImmutableArray[(Int, String)] = ImmutableArray(1, 2, 3).zip(ImmutableArray("a", "b")) | ||
|
||
assertEquals(ImmutableArray((1, "a"), (2, "b")), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsImmutableArrayAndIsEmpty = { | ||
val result: ImmutableArray[(Int, Int)] = ImmutableArray(1, 2, 3).zip(ImmutableArray.empty[Int]) | ||
|
||
assertTrue(result.isEmpty) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsOtherCollectionTypeAndHasSameNumberOfElements = { | ||
val result: ImmutableArray[(Int, String)] = ImmutableArray(1, 2, 3).zip(List("a", "b", "c")) | ||
|
||
assertEquals(ImmutableArray((1, "a"), (2, "b"), (3, "c")), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsOtherCollectionTypeAndHasMoreElements = { | ||
val result: ImmutableArray[(Int, String)] = ImmutableArray(1, 2).zip(List("a", "b", "c")) | ||
|
||
assertEquals(ImmutableArray((1, "a"), (2, "b")), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsOtherCollectionTypeAndHasLessElements = { | ||
val result: ImmutableArray[(Int, String)] = ImmutableArray(1, 2, 3).zip(List("a", "b")) | ||
|
||
assertEquals(ImmutableArray((1, "a"), (2, "b")), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWhenInputIsOtherCollectionTypeAndIsEmpty = { | ||
val result: ImmutableArray[(Int, Int)] = ImmutableArray(1, 2, 3).zip(List.empty[Int]) | ||
|
||
assertTrue(result.isEmpty) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsImmutableArrayAndHasSameNumberOfElements = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2, 3).zipWith(ImmutableArray(4, 5, 6))(_ + _) | ||
|
||
assertEquals(ImmutableArray(5, 7, 9), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsImmutableArrayAndHasMoreElements = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2).zipWith(ImmutableArray(4, 5, 6))(_ * _) | ||
|
||
assertEquals(ImmutableArray(4, 10), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsImmutableArrayAndHasLessElements = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2, 3).zipWith(ImmutableArray(4, 5))(_ + _) | ||
|
||
assertEquals(ImmutableArray(5, 7), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsImmutableArrayAndIsEmpty = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2, 3).zipWith(ImmutableArray.empty[Int])(_ % _) | ||
|
||
assertTrue(result.isEmpty) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsOtherCollectionTypeAndHasSameNumberOfElements = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2, 3).zipWith(List(4, 5, 6))(_ + _) | ||
|
||
assertEquals(ImmutableArray(5, 7, 9), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsOtherCollectionTypeAndHasMoreElements = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2).zipWith(List(4, 5, 6))(_ * _) | ||
|
||
assertEquals(ImmutableArray(4, 10), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsOtherCollectionTypeAndHasLessElements = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2, 3).zipWith(List(4, 5))(_ + _) | ||
|
||
assertEquals(ImmutableArray(5, 7), result) | ||
} | ||
|
||
@Test | ||
def hasCorrectZipWithWhenInputIsOtherCollectionTypeAndIsEmpty = { | ||
val result: ImmutableArray[Int] = ImmutableArray(1, 2, 3).zipWith(List.empty[Int])(_ % _) | ||
|
||
assertTrue(result.isEmpty) | ||
} | ||
} |
Oops, something went wrong.