-
Notifications
You must be signed in to change notification settings - Fork 96
/
Copy pathBasicsSpec.scala
69 lines (56 loc) · 1.7 KB
/
BasicsSpec.scala
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package com.evolutiongaming.bootcamp.basics
import Basics._
import org.scalatest.flatspec.AnyFlatSpec
import org.scalatest.matchers.should.Matchers._
import org.scalacheck.Arbitrary._
import org.scalatestplus.scalacheck.ScalaCheckDrivenPropertyChecks
class BasicsSpec extends AnyFlatSpec with ScalaCheckDrivenPropertyChecks {
"allBooleans" should "contain all possible boolean values" in {
allBooleans.size shouldEqual 2
allBooleans.reduce(_ && _) shouldEqual false
allBooleans.reduce(_ || _) shouldEqual true
}
"helloMethod" should "work for all strings" in {
forAll { x: String =>
helloMethod(x) shouldEqual s"Hello, $x!"
}
}
"helloFunction" should "work for all strings" in {
forAll { x: String =>
helloFunction(x) shouldEqual s"Hello, $x!"
}
}
"stringLength" should "work for all strings" in {
forAll { x: String =>
stringLength(x) shouldEqual x.length
}
}
"add" should "add 2 and 3" in {
add(2, 3) shouldEqual 5
}
it should "work for all numbers" in {
forAll { (a: Int, b: Int) =>
add(a, b) shouldEqual a + b
}
}
"power" should "be correct" in {
forAll { n: Int =>
power(2)(n) shouldEqual Math.pow(n.toDouble, 2)
}
forAll { n: Byte =>
power(3)(n.toInt) shouldEqual Math.pow(n.toDouble, 3)
}
}
"allOptionBooleans" should "be correct" in {
allOptionBooleans.size shouldEqual 3
}
"allEitherUnitBooleans" should "be correct" in {
allEitherUnitBooleans.size shouldEqual 3
}
"allEitherBooleanBooleans" should "be correct" in {
allEitherBooleanBooleans.size shouldEqual 4
}
"allTupleBooleanBooleans" should "be correct" in {
allTupleBooleanBooleans.size shouldEqual 4
}
}