Skip to content

Commit 0594da9

Browse files
fix: tests
1 parent 99c4dc1 commit 0594da9

File tree

2 files changed

+57
-59
lines changed

2 files changed

+57
-59
lines changed

src/test/kotlin/test/tests/hashers/ColleaguesTest.kt

Lines changed: 56 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import app.FactCodes
88
import app.hashers.CodeLine
99
import app.hashers.CodeLineAges
1010
import app.hashers.CodeLongevity
11+
import app.hashers.CommitCrawler
1112
import app.hashers.RevCommitLine
1213
import app.model.*
1314

@@ -40,31 +41,32 @@ class ColleaguesTest : Spek({
4041
val emails = hashSetOf(author1.email, author2.email)
4142

4243
val serverRepo = Repo(rehash = testRehash)
43-
val mockApi = MockApi(mockRepo = serverRepo)
44-
45-
testRepo.createFile(fileName, listOf("line1", "line2"))
46-
testRepo.commit(message = "initial commit",
47-
author = author1,
48-
date = Calendar.Builder().setTimeOfDay(0, 0, 0)
49-
.build().time)
50-
51-
testRepo.deleteLines(fileName, 1, 1)
52-
testRepo.commit(message = "delete line",
53-
author = author1,
54-
date = Calendar.Builder().setTimeOfDay(0, 1, 0)
55-
.build().time)
56-
57-
testRepo.deleteLines(fileName, 0, 0)
58-
testRepo.commit(message = "delete line #2",
59-
author = author2,
60-
date = Calendar.Builder().setTimeOfDay(0, 1, 0)
61-
.build().time)
62-
63-
val cl = CodeLongevity(serverRepo, emails, testRepo.git)
64-
cl.updateFromObservable(onError = { _ -> fail("exception") },
65-
api = mockApi)
6644

6745
it("'t1'") {
46+
val mockApi = MockApi(mockRepo = serverRepo)
47+
48+
testRepo.createFile(fileName, listOf("line1", "line2"))
49+
testRepo.commit(message = "initial commit",
50+
author = author1,
51+
date = Calendar.Builder().setTimeOfDay(0, 0, 0)
52+
.build().time)
53+
54+
testRepo.deleteLines(fileName, 1, 1)
55+
testRepo.commit(message = "delete line",
56+
author = author1,
57+
date = Calendar.Builder().setTimeOfDay(0, 1, 0)
58+
.build().time)
59+
60+
testRepo.deleteLines(fileName, 0, 0)
61+
testRepo.commit(message = "delete line #2",
62+
author = author2,
63+
date = Calendar.Builder().setTimeOfDay(0, 1, 0)
64+
.build().time)
65+
66+
val cl = CodeLongevity(serverRepo, emails, testRepo.git)
67+
cl.updateFromObservable(onError = { _ -> fail("exception") },
68+
api = mockApi)
69+
6870
val triple1 = cl.colleagues.get(author1.email)[0]
6971
assertEquals(triple1.first, author2.email,
7072
"Wrong colleague email #1")
@@ -95,40 +97,39 @@ class ColleaguesTest : Spek({
9597
val emails = hashSetOf(author1.email, author2.email)
9698

9799
val serverRepo = Repo(rehash = testRehash)
98-
val mockApi = MockApi(mockRepo = serverRepo)
99-
100-
testRepo.createFile(fileName, listOf("line1", "line2"))
101-
testRepo.commit(message = "initial commit",
102-
author = author1,
103-
date = Calendar.Builder().setTimeOfDay(0, 0, 0)
104-
.build().time)
105-
106-
testRepo.deleteLines(fileName, 1, 1)
107-
testRepo.commit(message = "delete line",
108-
author = author2,
109-
date = Calendar.Builder().setTimeOfDay(0, 1, 0)
110-
.build().time)
111-
112-
testRepo.insertLines(fileName, 1, listOf("line in the end"))
113-
testRepo.commit(message = "insert line",
114-
author = author2,
115-
date = Calendar.Builder().setTimeOfDay(0, 10, 0)
116-
.build().time)
117-
118-
testRepo.deleteLines(fileName, 1, 1)
119-
testRepo.commit(message = "delete line #2",
120-
author = author1,
121-
date = Calendar.Builder().setTimeOfDay(0, 20, 0)
122-
.build().time)
123-
124-
CodeLongevity(serverRepo, emails, testRepo.git)
125-
.updateFromObservable(onError = { _ -> fail("exception") },
126-
api = mockApi)
127100

128101
it("'t1'") {
129-
for (f in mockApi.receivedFacts) {
130-
println(f)
131-
}
102+
val mockApi = MockApi(mockRepo = serverRepo)
103+
104+
testRepo.createFile(fileName, listOf("line1", "line2"))
105+
testRepo.commit(message = "initial commit",
106+
author = author1,
107+
date = Calendar.Builder().setTimeOfDay(0, 0, 0)
108+
.build().time)
109+
110+
testRepo.deleteLines(fileName, 1, 1)
111+
testRepo.commit(message = "delete line",
112+
author = author2,
113+
date = Calendar.Builder().setTimeOfDay(0, 1, 0)
114+
.build().time)
115+
116+
testRepo.insertLines(fileName, 1, listOf("line in the end"))
117+
testRepo.commit(message = "insert line",
118+
author = author2,
119+
date = Calendar.Builder().setTimeOfDay(0, 10, 0)
120+
.build().time)
121+
122+
testRepo.deleteLines(fileName, 1, 1)
123+
testRepo.commit(message = "delete line #2",
124+
author = author1,
125+
date = Calendar.Builder().setTimeOfDay(0, 20, 0)
126+
.build().time)
127+
128+
CodeLongevity(serverRepo, emails, testRepo.git)
129+
.updateFromObservable(
130+
onError = { _ -> fail("exception") },
131+
api = mockApi)
132+
132133
assertTrue(mockApi.receivedFacts.contains(
133134
Fact(repo = serverRepo,
134135
code = FactCodes.COLLEAGUES,

src/test/kotlin/test/tests/hashers/CommitHasherTest.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ import java.io.File
1919
import java.util.stream.StreamSupport.stream
2020
import kotlin.streams.toList
2121
import kotlin.test.assertEquals
22-
import kotlin.test.assertNotEquals
2322

2423
class CommitHasherTest : Spek({
2524
fun getRepoRehash(git: Git, localRepo: LocalRepo): String {
@@ -246,13 +245,11 @@ class CommitHasherTest : Spek({
246245
"x = map(lambda x: x**2, range(10))," +
247246
"map(lambda x: x**3, range(10)))")
248247

249-
val authorEmail = "[email protected]"
250-
val author = Author("Test", authorEmail)
248+
val author = Author(userName, userEmail)
251249

252250
val testRepoPath = "../testrepo-commit-hasher-"
253251
val testRepo = TestRepo(testRepoPath + "python-facts")
254252

255-
val emails = hashSetOf(authorEmail)
256253
val mockApi = MockApi(mockRepo = repo)
257254
val observable = CommitCrawler.getObservable(testRepo.git, repo)
258255

0 commit comments

Comments
 (0)