Skip to content

Commit

Permalink
Address compiler warnings in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
dlindhol committed Jun 29, 2021
1 parent 5dc574f commit 2545a39
Show file tree
Hide file tree
Showing 38 changed files with 135 additions and 114 deletions.
4 changes: 2 additions & 2 deletions core/src/test/scala/TestEffects.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@

import cats.Id
import cats.effect._
//import cats.Id
//import cats.effect._
import fs2._

//resolver
Expand Down
9 changes: 5 additions & 4 deletions core/src/test/scala/latis/data/BinSetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,22 @@ package latis.data

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalatest.Inside.inside

class BinSetSpec extends AnyFlatSpec {

//Note, bin center semantics
val set1D = BinSet1D(0.0, 1.0, 10)

"A 1D bin set" should "have a min" in {
set1D.min match {
inside(set1D.min) {
case DomainData(Number(d)) =>
d should be(0.0)
}
}

it should "have a max" in {
set1D.max match {
inside(set1D.max) {
case DomainData(Number(d)) =>
d should be(9.0)
}
Expand All @@ -38,15 +39,15 @@ class BinSetSpec extends AnyFlatSpec {
val set2D = BinSet2D(set1D, set1D)

"A 2D linear set" should "have a min" in {
set2D.min match {
inside(set2D.min) {
case DomainData(Number(d1), Number(d2)) =>
d1 should be(0.0)
d2 should be(0.0)
}
}

"A 2D linear set" should "have a max" in {
set2D.max match {
inside(set2D.max) {
case DomainData(Number(d1), Number(d2)) =>
d1 should be(9.0)
d2 should be(9.0)
Expand Down
4 changes: 2 additions & 2 deletions core/src/test/scala/latis/data/CartesianFunctionSpec.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package latis.data

import Data._

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalatest.Inside.inside


class CartesianFunctionSpec extends AnyFlatSpec {
Expand All @@ -12,7 +12,7 @@ class CartesianFunctionSpec extends AnyFlatSpec {
val xs: IndexedSeq[Datum] = Vector(1.1, 2.2, 3.3).map(DoubleValue)
val x: Datum = DoubleValue(2.2)
CartesianFunction1D.fromData(xs, xs).map { f =>
f.eval(DomainData(x)) match {
inside(f.eval(DomainData(x))) {
case Right(RangeData(Number(d))) =>
d should be (2.2)
}
Expand Down
5 changes: 3 additions & 2 deletions core/src/test/scala/latis/data/DataSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package latis.data

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalatest.Inside.inside

class DataSpec extends AnyFlatSpec {

Expand Down Expand Up @@ -30,7 +31,7 @@ class DataSpec extends AnyFlatSpec {

"Implicitly constructed Boolean Data" should "be extractable through pattern matching" in {
val tup = TupleData(true, false)
tup match {
inside(tup) {
case TupleData(BooleanDatum(t), BooleanDatum(f)) =>
t should be(true)
f should be(false)
Expand All @@ -39,7 +40,7 @@ class DataSpec extends AnyFlatSpec {

"BooleanValues" should "be represented properly as Strings" in {
val tup = TupleData(true, false)
tup match {
inside(tup) {
case TupleData(t: Data.BooleanValue, f: Data.BooleanValue) =>
t.asString should be("true")
f.asString should be("false")
Expand Down
9 changes: 5 additions & 4 deletions core/src/test/scala/latis/data/LinearSetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,21 @@ package latis.data

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalatest.Inside.inside

class LinearSetSpec extends AnyFlatSpec {

val set1D = LinearSet1D(0.0, 1.0, 10)

"A 1D linear set" should "have a min" in {
set1D.min match {
inside(set1D.min) {
case DomainData(Number(d)) =>
d should be(0.0)
}
}

it should "have a max" in {
set1D.max match {
inside(set1D.max) {
case DomainData(Number(d)) =>
d should be(9.0)
}
Expand All @@ -37,15 +38,15 @@ class LinearSetSpec extends AnyFlatSpec {
val set2D = LinearSet2D(set1D, set1D)

"A 2D linear set" should "have a min" in {
set2D.min match {
inside(set2D.min) {
case DomainData(Number(d1), Number(d2)) =>
d1 should be (0.0)
d2 should be (0.0)
}
}

"A 2D linear set" should "have a max" in {
set2D.max match {
inside(set2D.max) {
case DomainData(Number(d1), Number(d2)) =>
d1 should be (9.0)
d2 should be (9.0)
Expand Down
17 changes: 9 additions & 8 deletions core/src/test/scala/latis/dataset/DatasetSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import java.nio.file.Paths
import cats.effect.unsafe.implicits.global
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalatest.Inside.inside

import latis.catalog.FdmlCatalog
import latis.data.Data._
Expand Down Expand Up @@ -34,8 +35,8 @@ class DatasetSpec extends AnyFlatSpec {

val data = {
val samples = List(
Sample(DomainData(1l), RangeData(1.2d)),
Sample(DomainData(2l), RangeData(2.4d))
Sample(DomainData(1L), RangeData(1.2D)),
Sample(DomainData(2L), RangeData(2.4D))
)
SampledFunction(samples)
}
Expand All @@ -48,20 +49,20 @@ class DatasetSpec extends AnyFlatSpec {
}

it should "provide a sample" in {
StreamUtils.unsafeHead(dataset.samples) match {
inside(StreamUtils.unsafeHead(dataset.samples)) {
case Sample(DomainData(lv: Data.LongValue), RangeData(dv: Data.DoubleValue)) =>
lv.value should be (1l)
dv.value should be (1.2d)
lv.value should be (1L)
dv.value should be (1.2D)
}
}

it should "apply an operation" in {
val select = Selection(id"time", ast.Gt, "1")
val ds2 = dataset.withOperation(select)
StreamUtils.unsafeHead(ds2.samples) match {
inside(StreamUtils.unsafeHead(ds2.samples)) {
case Sample(DomainData(lv: Data.LongValue), RangeData(dv: Data.DoubleValue)) =>
lv.value should be (2l)
dv.value should be (2.4d)
lv.value should be (2L)
dv.value should be (2.4D)
}
}

Expand Down
11 changes: 6 additions & 5 deletions core/src/test/scala/latis/dsl/DatasetGeneratorSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package latis.dsl

import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalatest.Inside.inside

import latis.data._
import latis.data.Data._
Expand All @@ -16,13 +17,13 @@ class DatasetGeneratorSpec extends AnyFlatSpec {

val ds = DatasetGenerator.generate1DDataset(xs, as, bs)
ds.model.toString should be ("_1 -> (a, b)")
ds.model match {
inside(ds.model) {
case Function(x: Scalar, Tuple(a: Scalar, b: Scalar)) =>
x.valueType should be (IntValueType)
a.valueType should be (StringValueType)
b.valueType should be (DoubleValueType)
}
ds.data.sampleSeq.head match {
inside(ds.data.sampleSeq.head) {
case Sample(DomainData(x: IntValue), RangeData(a: StringValue, b: DoubleValue)) =>
x.value should be (1)
a.value should be ("a")
Expand All @@ -38,14 +39,14 @@ class DatasetGeneratorSpec extends AnyFlatSpec {

val ds = DatasetGenerator.generate2DDataset(xs, ys, as, bs)
ds.model.toString should be ("(_1, _2) -> (a, b)")
ds.model match {
inside(ds.model) {
case Function(Tuple(x: Scalar, y: Scalar), Tuple(a: Scalar, b: Scalar)) =>
x.valueType should be (CharValueType)
y.valueType should be (IntValueType)
a.valueType should be (StringValueType)
b.valueType should be (DoubleValueType)
}
ds.data.sampleSeq.head match {
inside(ds.data.sampleSeq.head) {
case Sample(DomainData(x: CharValue, y: IntValue), RangeData(a: StringValue, b: DoubleValue)) =>
x.value should be ('a')
y.value should be (1)
Expand All @@ -69,7 +70,7 @@ class DatasetGeneratorSpec extends AnyFlatSpec {

val ds = DatasetGenerator.generate3DDataset(xs, ys, zs, as, bs)
ds.model.toString should be ("(_1, _2, _3) -> (a, b)")
ds.model match {
inside(ds.model) {
case Function(Tuple(x: Scalar, y: Scalar, z: Scalar), Tuple(a: Scalar, b: Scalar)) =>
x.valueType should be (CharValueType)
y.valueType should be (IntValueType)
Expand Down
9 changes: 5 additions & 4 deletions core/src/test/scala/latis/dsl/ModelParserSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import atto.Atto._
import org.scalactic.Equality
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalatest.Inside.inside

import latis.metadata.Metadata
import latis.model.DataType
Expand Down Expand Up @@ -51,7 +52,7 @@ class ModelParserSpec extends AnyFlatSpec {
}

it should "parse a nested tuple" in {
ModelParser.unsafeParse("(a, (b, c))") match {
inside(ModelParser.unsafeParse("(a, (b, c))")) {
case Tuple(a: Scalar, Tuple(b: Scalar, c: Scalar)) =>
a.id.get should be (id"a")
b.id.get should be (id"b")
Expand All @@ -60,7 +61,7 @@ class ModelParserSpec extends AnyFlatSpec {
}

ignore should "parse a function in a tuple" in {
ModelParser.unsafeParse("(a, b -> c)") match {
inside(ModelParser.unsafeParse("(a, b -> c)")) {
case Tuple(a: Scalar, Function(b: Scalar, c: Scalar)) =>
a.id.get should be (id"a")
b.id.get should be (id"b")
Expand Down Expand Up @@ -121,7 +122,7 @@ class ModelParserSpec extends AnyFlatSpec {
}

it should "make an exception for an invalid model expression" in {
ModelParser.parse("a <- b") match {
inside(ModelParser.parse("a <- b")) {
case Left(le: LatisException) =>
le.message.take(6) should be("Failed")
}
Expand All @@ -148,7 +149,7 @@ class ModelParserSpec extends AnyFlatSpec {
* Partially apply with a parser to get a function that takes the string you
* want to parse and the thing you expect to get back
*/
private def testParser[A](p: Parser[A])(s: String, d: A): Unit = p.parseOnly(s) match {
private def testParser[A](p: Parser[A])(s: String, d: A): Any = p.parseOnly(s) match {
case ParseResult.Done(_, result: DataType) => result should equal(d)
case ParseResult.Done(_, result) => result should be(d)
case ParseResult.Fail(_, _, m) => fail(s"$m in $s")
Expand Down
23 changes: 12 additions & 11 deletions core/src/test/scala/latis/input/FileListAdapterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
}

val samples: List[Sample] =
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync()

val expected: List[Sample] = List(
Sample(DomainData("2010"), RangeData(root.resolve("2010-a").toUri().toString())),
Expand Down Expand Up @@ -75,7 +75,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
}

val samples: List[Sample] =
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync()

val expected: List[Sample] = List(
Sample(DomainData("2010"), RangeData(root.resolve("a/2010-a").toUri().toString())),
Expand Down Expand Up @@ -113,7 +113,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
)

val samples: List[Sample] =
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync()

samples should contain theSameElementsAs (expected)
}
Expand Down Expand Up @@ -145,12 +145,12 @@ class FileListAdapterSpec extends AnyFlatSpec {
}

val samples: List[Sample] =
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync()

val expected: List[Sample] = List(
Sample(DomainData("2010"), RangeData(root.resolve("2010-a").toUri().toString(), 0l)),
Sample(DomainData("2011"), RangeData(root.resolve("2011-b").toUri().toString(), 0l)),
Sample(DomainData("2012"), RangeData(root.resolve("2012-c").toUri().toString(), 0l))
Sample(DomainData("2010"), RangeData(root.resolve("2010-a").toUri().toString(), 0L)),
Sample(DomainData("2011"), RangeData(root.resolve("2011-b").toUri().toString(), 0L)),
Sample(DomainData("2012"), RangeData(root.resolve("2012-c").toUri().toString(), 0L))
)

samples should contain theSameElementsAs (expected)
Expand Down Expand Up @@ -183,7 +183,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
)

val samples: List[Sample] =
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync()

samples should contain theSameElementsAs (expected)
}
Expand Down Expand Up @@ -221,7 +221,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
)

val samples: List[Sample] =
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync()

samples should contain theSameElementsAs (expected)
}
Expand Down Expand Up @@ -263,7 +263,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
)

val samples: List[Sample] =
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(root.toUri()).samples.compile.toList.unsafeRunSync()

samples should contain theSameElementsAs (expected)
}
Expand Down Expand Up @@ -312,7 +312,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
// Run the test.
withTmpDir(root) { dir =>
val samples: List[Sample] =
adapter.getData(dir.toUri()).samples.compile.toList.unsafeRunSync
adapter.getData(dir.toUri()).samples.compile.toList.unsafeRunSync()

samples should contain theSameElementsAs (expected)
}
Expand Down Expand Up @@ -388,6 +388,7 @@ class FileListAdapterSpec extends AnyFlatSpec {
}

Files.walkFileTree(tmp, visitor)
() //return Unit to keep the compiler happy
}

private def withFlatDir(f: Path => Any): Any = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@ final class GranuleListAppendAdapterSpec extends AnyFlatSpec {
.samples
.compile
.toList
.unsafeRunSync
.unsafeRunSync()

val gSamples = (g1.samples ++ g2.samples ++ g3.samples)
.compile
.toList
.unsafeRunSync
.unsafeRunSync()

glaSamples should equal (gSamples)
}
Expand Down
Loading

0 comments on commit 2545a39

Please sign in to comment.