Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions 8-ci-travis/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
.gradle
/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties
7 changes: 7 additions & 0 deletions 8-ci-travis/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: java

jdk: openjdk8

install: gradle build

script: gradle test
20 changes: 20 additions & 0 deletions 8-ci-travis/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
**building/compiling code**

1. gradlew build

**running tests**

2. gradle test

**reporting dependencies**

3. gradle dependencies

>filtering output

4. gradle dependencies --configuration testCompileClasspath
5. gradle dependencyInsight --configuration testCompileClasspath --dependency junit

**generating wrapper files**

6. gradle wrapper
11 changes: 11 additions & 0 deletions 8-ci-travis/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
apply plugin: 'java'

repositories {
mavenCentral()
}

dependencies {
testImplementation 'junit:junit:4.1', 'org.hamcrest:hamcrest-all:1.3'
}


172 changes: 172 additions & 0 deletions 8-ci-travis/gradlew

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions 8-ci-travis/gradlew.bat

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

21 changes: 21 additions & 0 deletions 8-ci-travis/src/main/java/example/BinarySearch.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package example;

public class BinarySearch {

public static int binarySearch(int[] a, int key) {
int low = 0;
int high = a.length - 1;
while (low <= high) {
int mid = (low + high) / 2;
int midVal = a[mid];
if (midVal < key)
low = mid + 1;
else if (midVal > key)
high = mid - 1;
else
return mid; // key found
}
return -(low + 1); // key not found.
}

}
45 changes: 45 additions & 0 deletions 8-ci-travis/src/test/java/example/BinarySearchTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package example;

import org.junit.Test;
import org.junit.Assert;
import org.junit.Before;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;

import java.util.Arrays;

public class BinarySearchTest {

int[] a;

@Before
public void setup() {
a = new int[]{7,9,1,3,5,13,20,55,255,127};
Arrays.sort(a);
}

@Test
public void elementFound() {
// junit style
Assert.assertEquals(2, BinarySearch.binarySearch(a, 5));
// hamcrest style
assertThat(BinarySearch.binarySearch(a, 20), is(6));
}

@Test
public void elementNotFound() {
assertThat(BinarySearch.binarySearch(a, 15), is(lessThan(0)));
}

@Test
public void emptyArray() {
assertThat(BinarySearch.binarySearch(new int[]{}, 99), is(lessThan(0)));
}

@Test(expected=NullPointerException.class)
public void nullArray() {
BinarySearch.binarySearch(null, 99);
}

}