Skip to content

Commit

Permalink
objective tests added
Browse files Browse the repository at this point in the history
  • Loading branch information
Felix Reimann committed Jan 26, 2018
1 parent ee02777 commit 7d70b75
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ task jacocoRootReport(type: org.gradle.testing.jacoco.tasks.JacocoReport) {
}
afterEvaluate {
classDirectories = files(classDirectories.files.collect {
fileTree(dir: it, exclude: ['ptolemy/**', 'org/opt4j/tutorial/**'])
fileTree(dir: it, exclude: ['ptolemy/**', 'org/opt4j/tutorial/**', 'org/opt4j/viewer/**', 'org/opt4j/core/config/visualization/**'])
})
}
}
Expand Down
70 changes: 70 additions & 0 deletions opt4j-core/src/test/java/org/opt4j/core/ObjectiveTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package org.opt4j.core;

import org.junit.Assert;
import org.junit.Test;
import org.opt4j.core.Objective.Sign;

public class ObjectiveTest {

@Test
public void getSignTest() {
Objective o = new Objective("obj", Sign.MAX);
Assert.assertEquals(Sign.MAX, o.getSign());
}

@Test
public void getNameTest() {
Objective o = new Objective("obj", Sign.MAX);
Assert.assertEquals("obj", o.getName());
}

@Test
public void equalsTest() {
Objective o1 = new Objective("obj1", Sign.MAX);
Objective o11 = new Objective("obj1", Sign.MAX);
Objective o2 = new Objective("obj2", Sign.MAX);
Objective o3 = new Objective("obj1", Sign.MIN);
Objective o4 = new Objective(null, Sign.MAX);
Objective o5 = new Objective(null, Sign.MAX);

Assert.assertEquals(o1, o1);
Assert.assertEquals(o1, o11);
Assert.assertEquals(o4, o5);
Assert.assertNotEquals(o1, null);
Assert.assertNotEquals(o1, "something else");
Assert.assertNotEquals(o1, o2);
Assert.assertNotEquals(o1, o3);
Assert.assertNotEquals(o4, o3);
}

@Test
public void hashCodeTest() {
String name = "obj1";
Objective o1 = new Objective(name, Sign.MAX);
Objective o2 = new Objective(name, Sign.MAX);
Objective o3 = new Objective(null, Sign.MAX);
Objective o4 = new Objective(name, null);

Assert.assertEquals(o1.hashCode(), o2.hashCode());
Assert.assertNotEquals(o1.hashCode(), o3.hashCode());
Assert.assertNotEquals(o1.hashCode(), o4.hashCode());
}

@Test
public void compareToTest() {
Objective o1 = new Objective("obj1", Sign.MAX);
Objective o11 = new Objective("obj1", Sign.MAX);
Objective o2 = new Objective("obj2", Sign.MAX);

Assert.assertEquals(0, o1.compareTo(o11));
Assert.assertEquals(-1 * o1.compareTo(o2), o2.compareTo(o1));
Assert.assertEquals(1, o1.compareTo(null));
}

@Test
public void toStringTest() {
Objective o = new Objective("obj", Sign.MAX);
Assert.assertEquals("obj(MAX)", o.toString());
}

}

0 comments on commit 7d70b75

Please sign in to comment.