Skip to content

Commit d46455c

Browse files
authored
Merge pull request #21 from bearmug/20-revert-to-full-code-coverage
#20 fix failed code coverage
2 parents 0eb3046 + 5af7008 commit d46455c

File tree

3 files changed

+20
-5
lines changed

3 files changed

+20
-5
lines changed

src/main/scala/org/bearmug/algo/course01/week04/Karger.scala

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ class Karger(m: Map[Int, List[Int]]) {
2828
}
2929

3030
m match {
31-
case e if e.isEmpty => Int.MaxValue
32-
case _ => (0 until m.size).map { _ => calcCut(m, m.keys.toVector) } min
31+
case _ => (0 until (m.size max 10)).map { _ => calcCut(m, m.keys.toVector) }.min
3332
}
3433
}
3534
}
@@ -38,8 +37,12 @@ object Karger {
3837
def apply(m: Map[Int, List[Int]]): Karger = new Karger(m)
3938

4039
def apply(fileName: String): Karger =
41-
apply(Source.fromURL(getClass.getResource(fileName)).getLines().map{ _.split("\t").map(_.toInt).toList match {
42-
case n :: rest => n -> rest
43-
}}.toMap)
40+
apply(Source.fromURL(getClass.getResource(fileName))
41+
.getLines()
42+
.map(_
43+
.split("\t")
44+
.map(_.toInt)
45+
.toList)
46+
.map(l => l.head -> l.tail).toMap)
4447
}
4548

src/test/scala/org/bearmug/algo/course01/week02/InversionsSuite.scala

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,14 @@ class InversionsSuite extends FunSuite {
6767
assert(Inversions((1 to 100000 reverse).toVector).inversionsPar(4) == (100000 / 2) * (100000 - 1))
6868
}
6969

70+
test("inversionsForce works for single element") {
71+
assert(Inversions(Vector(1)).inversionsForce() == 0)
72+
}
73+
74+
test("inversionsForce works for of non-inversed elements") {
75+
assert(Inversions(Vector(1, 2, 3)).inversionsForce() == 0)
76+
}
77+
7078
test("inversionsForce works for of three two inversed elements") {
7179
assert(Inversions(Vector(3, 2, 1)).inversionsForce() == 3)
7280
}

src/test/scala/org/bearmug/algo/course01/week04/KargerSuite.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ class KargerSuite extends FunSuite {
1010
assert(Karger(Map[Int, List[Int]]()).minCut() == Int.MaxValue)
1111
}
1212

13+
test("minCut works for one-node graph") {
14+
assert(Karger(Map(1 -> List(2))).minCut() == Int.MaxValue)
15+
}
16+
1317
test("minCut works for two-nodes graph") {
1418
assert(Karger(Map(1 -> List(2), 2 -> List(1))).minCut() == 1)
1519
}

0 commit comments

Comments
 (0)