Skip to content

Commit fa5dcaa

Browse files
author
Jan Paw
committed
SCL-4: mocking and vectorization tests
1 parent 96e56c5 commit fa5dcaa

File tree

4 files changed

+32
-38
lines changed

4 files changed

+32
-38
lines changed

project/ScalaCLBuild.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ object ScalaCLBuild extends Build {
7171
// "-optimise",
7272
"-deprecation",
7373
"-feature",
74-
// "-Xlog-free-types",
74+
// "-Xlog-free-types",q
7575
// "-Ymacro-debug-lite",
7676
"-unchecked"
7777
),
@@ -81,6 +81,7 @@ object ScalaCLBuild extends Build {
8181
libraryDependencies ++= Seq(
8282
"junit" % "junit" % "4.10" % "test",
8383
"org.scalatest" % "scalatest_2.11" % "2.2.1" % "test",
84+
"org.scalamock" % "scalamock-scalatest-support_2.11" % "3.1.2",
8485
"com.novocode" % "junit-interface" % "0.8" % "test"
8586
)
8687
)

src/test/scala/scalacl/BaseTest.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package scalacl
22

33
import org.scalatest.{ FlatSpecLike, Matchers }
4+
import org.scalamock.scalatest.MockFactory
45

5-
trait BaseTest extends FlatSpecLike with Matchers {
6+
trait BaseTest extends FlatSpecLike with Matchers with MockFactory{
67
def context[T](f: Context => T): T = {
78
val context = Context.best
89
try {

src/test/scala/scalacl/KernelTest.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,8 @@
2929
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3030
*/
3131
package scalacl
32-
import impl._
3332

34-
import org.junit._
35-
import Assert._
33+
import scalacl.impl.KernelDef
3634

3735
class KernelTest extends BaseTest {
3836
behavior of "ScalaCl kernel"
@@ -66,6 +64,7 @@ class KernelTest extends BaseTest {
6664
for (i <- 0L until n by 3L)
6765
clResult(i) = i * f + 10
6866
}
67+
6968
for (i <- 0L until n by 3L)
7069
result(i.toInt) = i * f + 10
7170

src/test/scala/scalacl/impl/VectorizationTest.scala

Lines changed: 26 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -33,21 +33,20 @@ package impl
3333

3434
import scalaxy.components._
3535

36-
import org.junit._
37-
import Assert._
38-
import org.hamcrest.CoreMatchers._
39-
4036
class VectorizationTest
41-
extends Vectorization
37+
extends BaseTest
38+
with Vectorization
4239
with WithRuntimeUniverse
4340
with WithTestFresh {
41+
42+
behavior of "ScalaCl vectorization"
43+
4444
import global._
4545

4646
private val context = reify { null: Context }
47-
private val NotVectorizable: Option[Expr[Unit]] = None
48-
private val Vectorizable = not(NotVectorizable)
47+
private val vectorized: Option[Expr[Unit]] = mock[Some[Expr[Unit]]]
4948

50-
private def vec(block: Expr[Unit]) = {
49+
private def afterVectorization(block: Expr[Unit]): Option[global.Expr[Unit]] = {
5150
try {
5251
vectorize(context, typeCheck(block.tree, WildcardType))
5352
} catch {
@@ -57,34 +56,28 @@ class VectorizationTest
5756
}
5857
}
5958

60-
@Test
61-
def notVectorizable0D() {
62-
assertThat(
63-
vec(reify { 1 + 2 }),
64-
is(NotVectorizable)
65-
)
59+
it should "not vectorized 0D expression" in {
60+
afterVectorization(reify { 1 + 2 }) should not be vectorized
61+
}
62+
63+
it should "vectorized 1D expression" in {
64+
afterVectorization(reify {
65+
for (i <- 0 until 10) i + 1
66+
}) should be (vectorized)
6667
}
6768

68-
@Test
69-
def vectorizable1D() {
70-
assertThat(
71-
vec(reify {
72-
for (i <- 0 until 10) i + 2
73-
}),
74-
is(Vectorizable)
75-
)
69+
it should "vectorized 2D expression" in {
70+
afterVectorization(reify {
71+
for (i <- 0 until 10; j <- 0 until 10)
72+
i + j + 2
73+
}) should be (vectorized)
7674
}
7775

78-
// @Ignore
79-
@Test
80-
def notVectorizable2D() {
81-
assertThat(
82-
vec(reify {
83-
for (i <- 0 until 10; j <- 0 until 10)
84-
i + j + 2
85-
}),
86-
//is(NotVectorizable)
87-
is(Vectorizable)
88-
)
76+
ignore should "vectorized 3D expression" in {
77+
afterVectorization(reify {
78+
for (i <- 0 until 10; j <- 0 until 10; k <- 0 until 10)
79+
i + j + k + 3
80+
}) should be (vectorized)
8981
}
82+
9083
}

0 commit comments

Comments
 (0)