-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
1 changed file
with
50 additions
and
0 deletions.
There are no files selected for viewing
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,50 @@ | ||
import zio.test._ | ||
import zio.test.Assertion._ | ||
import zio.Chunk | ||
import GlobalStatisticsAnalysis._ | ||
import java.time.LocalDate | ||
|
||
object GlobalStatsSpec extends ZIOSpecDefault { | ||
def getTestPath(filename: String): String = { | ||
getClass.getClassLoader.getResource(filename).getFile() | ||
} | ||
|
||
def spec: Spec[TestEnvironment, Any] = suite("GlobalStatistics")( | ||
test("getFieldsStatistics should return empty list if no data in period") { | ||
val data = Chunk( | ||
(LocalDate.of(2021, 1, 1), 1.0f), | ||
(LocalDate.of(2021, 1, 2), 2.0f) | ||
) | ||
val fields = List( | ||
FieldSelector("fieldName", (x: (LocalDate, Float)) => x._2) | ||
) | ||
val start = LocalDate.of(2022, 1, 1) | ||
val end = LocalDate.of(2022, 12, 31) | ||
val result = GlobalStatisticsAnalysis.getFieldsStatistics(data, fields, (x: (LocalDate, Float)) => x._1, start, end) | ||
assert(result)(equalTo(Nil)) | ||
}, | ||
test("getFieldsStatistics should return correct statistics") { | ||
val data = Chunk( | ||
(LocalDate.of(2021, 1, 1), 1.0f), | ||
(LocalDate.of(2021, 1, 2), 2.0f) | ||
) | ||
val fields = List( | ||
FieldSelector("fieldName", (x: (LocalDate, Float)) => x._2) | ||
) | ||
val start = LocalDate.of(2021, 1, 1) | ||
val end = LocalDate.of(2021, 1, 2) | ||
val result = GlobalStatisticsAnalysis.getFieldsStatistics(data, fields, (x: (LocalDate, Float)) => x._1, start, end) | ||
assert(result)(equalTo(List(Statistics("fieldName", 1.5, 0.5, 1.0, 2.0, 2)))) | ||
}, | ||
test("getFieldsStatistics should return empty list if empty data") { | ||
val data = Chunk.empty | ||
val fields = List( | ||
FieldSelector("fieldName", (x: (LocalDate, Float)) => x._2) | ||
) | ||
val start = LocalDate.of(2021, 1, 1) | ||
val end = LocalDate.of(2021, 1, 2) | ||
val result = GlobalStatisticsAnalysis.getFieldsStatistics(data, fields, (x: (LocalDate, Float)) => x._1, start, end) | ||
assert(result)(equalTo(Nil)) | ||
} | ||
) | ||
} |