-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyTests.test.scala
73 lines (58 loc) · 2.1 KB
/
MyTests.test.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
70
71
72
73
package example
import scala.concurrent.ExecutionContext.Implicits.global
import scala.util.Properties
import java.nio.file.NoSuchFileException
class MyTests extends munit.FunSuite:
test("sum of two integers"):
val obtained = 2 + 2
val expected = 4
assertEquals(obtained, expected)
test("all even numbers"):
val input: List[Int] = List(1, 2, 3, 4)
val obtainedResults: List[Int] = input.map(_ * 2)
// check that obtained values are all even numbers
assert(obtainedResults.forall(x => x % 2 == 0))
test("failing test".ignore):
val obtained = 2 + 3
val expected = 4
assertEquals(obtained, expected)
test("requests".flaky.ignore):
// I/O heavy tests that sometimes fail
???
class MathSuite extends munit.FunSuite:
test("addition"):
assert(1 + 1 == 2)
test("multiplication".only):
assert(3 * 7 == 21)
test("remainder"):
assert(13 % 5 == 3)
class FileTests extends munit.FunSuite:
test("read missing file"):
val missingFile = os.pwd / "missing.txt"
// the code that should throw an exception
val exception = intercept[NoSuchFileException](os.read(missingFile))
assert(clue(exception.getMessage).contains("missing.txt"))
val usingTempFile: FunFixture[os.Path] = FunFixture(
setup = _ => os.temp(prefix = "file-tests"),
teardown = tempFile => os.remove(tempFile)
)
usingTempFile.test("overwrite on file"): tempFile =>
os.write.over(tempFile, "Hello, World!")
val obtained = os.read(tempFile)
assertEquals(obtained, "Hello, World!")
val using2TempFiles: FunFixture[(os.Path, os.Path)] =
FunFixture.map2(usingTempFile, usingTempFile)
using2TempFiles.test("merge two files".ignore): (file1, file2) =>
// body of the test
???
test("home directory"):
assume(Properties.isLinux, "this test runs only on Linux")
assert(os.home.toString.startsWith("/home/"))
class AsyncMathLibTests extends munit.FunSuite:
test("square"):
for
squareOf3 <- AsyncMathLib.square(3)
squareOfMinus4 <- AsyncMathLib.square(-4)
yield
assertEquals(squareOf3, 9)
assertEquals(squareOfMinus4, 16)