Skip to content

Commit 46aa813

Browse files
authored
Merge pull request #53 from khanhhuynguyenvu/new_branch
fix(travis): travis automation testing
2 parents dc10100 + 54d922d commit 46aa813

File tree

5 files changed

+53
-8
lines changed

5 files changed

+53
-8
lines changed

.travis.yml

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
1+
dist: trusty
2+
13
language: scala
4+
25
scala:
3-
- 2.9.3
4-
- 2.10.6
5-
- 2.11.11
6+
- 2.13.1
7+
8+
jdk:
9+
- openjdk8

src/main/scala/Search/BinarySearch.scala

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,4 +44,33 @@ object BinarySearch {
4444

4545
SearchImpl(fromIndex, toIndex - 1)
4646
}
47+
48+
/**
49+
*
50+
* @param arr - a sequence of integers
51+
* @param elem - a integer to search for in the @args
52+
* @return
53+
*/
54+
def lowerBound(arr: List[Int], elem: Int): Int = {
55+
lowerBound(arr, elem, 0, arr.length - 1)
56+
}
57+
58+
/**
59+
*
60+
* @param arr - a sequence of integers
61+
* @param elem - a integer to search for in the @args
62+
* @param lo - lowest value index
63+
* @param hi - highest value index
64+
* @return
65+
*/
66+
def lowerBound(arr: List[Int], elem: Int, lo: Int, hi: Int): Int = {
67+
if (lo == hi) lo
68+
else {
69+
val m: Int = lo + (hi - lo) / 2
70+
arr(m) match {
71+
case mv if (mv < elem) => lowerBound(arr, elem, m + 1, hi)
72+
case mv if (mv >= elem) => lowerBound(arr, elem, lo, m)
73+
}
74+
}
75+
}
4776
}

src/test/scala/Mathematics/FindMaxSpec.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import org.scalatest.FlatSpec
44

55
class FindMaxSpec extends FlatSpec {
66

7-
it should "output the correct Integer as a result from the list of elements" in {
7+
"FindMaxSpec 1" should "output the correct Integer as a result from the list of elements" in {
88
assert(FindMax.findMax(List(-1000, -1, 999, 72, 65, -56, -767)) === 999)
99
}
1010

11-
it should "output the correct Integer as a result from the list of elements" in {
11+
"FindMaxSpec 2" should "output the correct Integer as a result from the list of elements" in {
1212
assert(FindMax.findMax(List(121, 221, 3, 4112)) === 4112)
1313
}
1414

src/test/scala/Mathematics/FindMinSpec.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ import org.scalatest.FlatSpec
44

55
class FindMinSpec extends FlatSpec {
66

7-
it should "output the correct Integer as a result from the list of elements" in {
7+
"FindMinSpec 1" should "output the correct Integer as a result from the list of elements" in {
88
assert(FindMin.findMin(List(-1000, -1, 999, 72, 65, -56, -767)) === -1000)
99
}
10-
11-
it should "output the correct Integer as a result from the list of elements" in {
10+
1
11+
"FindMinSpec 2" should "output the correct Integer as a result from the list of elements" in {
1212
assert(FindMin.findMin(List(121, 221, 3, 4112)) === 3)
1313
}
1414

src/test/scala/Search/BinarySearchSpec.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,16 @@ class BinarySearchSpec extends FlatSpec {
3232
assert(BinarySearch.binarySearch(l, 7, 0, 4) === -1)
3333
assert(BinarySearch.binarySearch(l, 7, 1, 3) === -1)
3434
}
35+
36+
"A lower Bound" should "return the index of first appearance element" in {
37+
val m = List(1, 3, 5, 5, 5, 9, 9, 13, 13, 20)
38+
assert(BinarySearch.lowerBound(m, 5) === 2)
39+
assert(BinarySearch.lowerBound(m, 9) === 5)
40+
}
41+
"A lower bound" should "return the index of number larger than an element and which is smallest" in {
42+
val m = List(1, 3, 5, 5, 5, 9, 9, 13, 13, 20)
43+
assert(BinarySearch.lowerBound(m, 4) === 2)
44+
assert(BinarySearch.lowerBound(m, 8) === 5)
45+
assert(BinarySearch.lowerBound(m, 10) === 7)
46+
}
3547
}

0 commit comments

Comments
 (0)