-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Compute matrix diagonal on normalization #252
- Loading branch information
Showing
6 changed files
with
116 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 14 additions & 0 deletions
14
src/main/java/org/rulez/demokracia/pdengine/Normalizable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package org.rulez.demokracia.pdengine; | ||
import org.rulez.demokracia.pdengine.dataobjects.Pair; | ||
|
||
public interface Normalizable extends ContainingBeats { | ||
|
||
long serialVersionUID = 1L; | ||
|
||
default void normalize() { | ||
for (String key : getKeyCollection()) { | ||
setElement(key, key, new Pair(0, 0)); | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
src/test/java/org/rulez/demokracia/pdengine/BaseEntityHashEqualsTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package org.rulez.demokracia.pdengine; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import org.junit.Test; | ||
import org.rulez.demokracia.pdengine.annotations.TestedBehaviour; | ||
import org.rulez.demokracia.pdengine.annotations.TestedFeature; | ||
import org.rulez.demokracia.pdengine.annotations.TestedOperation; | ||
import org.rulez.demokracia.pdengine.dataobjects.Pair; | ||
import org.rulez.demokracia.pdengine.dataobjects.VoteEntity; | ||
|
||
@TestedFeature("Supporting functionality") | ||
@TestedOperation("BaseEntity") | ||
@TestedBehaviour("None of the entities count id into the equals and hashCode.") | ||
public class BaseEntityHashEqualsTest { | ||
|
||
|
||
@Test | ||
public void entities_with_equal_fields_are_equal() { | ||
Pair pair1 = new Pair(12, 42); | ||
Pair pair2 = new Pair(12, 42); | ||
assertNotEquals(pair1.id, pair2.id); | ||
assertEquals(pair1, pair2); | ||
} | ||
|
||
@Test | ||
public void entities_with_different_fields_are_not_equal() { | ||
Pair pair1 = new Pair(12, 42); | ||
Pair pair2 = new Pair(12, 69); | ||
assertNotEquals(pair1, pair2); | ||
} | ||
|
||
@Test | ||
public void equal_entities_have_the_same_hash_code() { | ||
Pair pair1 = new Pair(12, 42); | ||
Pair pair2 = new Pair(12, 42); | ||
assertEquals(pair1.hashCode(), pair2.hashCode()); | ||
} | ||
|
||
@Test | ||
public void hashCode_should_return_different_hash_on_different_entities() { | ||
Pair pair = new Pair(10, 10); | ||
VoteEntity vote = new VoteEntity(); | ||
assertNotEquals(pair.hashCode(), vote.hashCode()); | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/test/java/org/rulez/demokracia/pdengine/BeatTableNormalizationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package org.rulez.demokracia.pdengine; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.rulez.demokracia.pdengine.annotations.TestedBehaviour; | ||
import org.rulez.demokracia.pdengine.annotations.TestedFeature; | ||
import org.rulez.demokracia.pdengine.annotations.TestedOperation; | ||
import org.rulez.demokracia.pdengine.dataobjects.Pair; | ||
import org.rulez.demokracia.pdengine.exception.ReportedException; | ||
import org.rulez.demokracia.pdengine.testhelpers.CreatedBeatTable; | ||
|
||
@TestedFeature("Schulze method") | ||
@TestedOperation("normalize beat matrix") | ||
public class BeatTableNormalizationTest extends CreatedBeatTable { | ||
|
||
@Override | ||
@Before | ||
public void setUp() throws ReportedException { | ||
super.setUp(); | ||
createNewBeatTableWithComplexData(); | ||
} | ||
|
||
@TestedBehaviour("the diagonal elements are (0,0)") | ||
@Test | ||
public void normalization_sets_the_diagonal_to_0_0() { | ||
beatTable.normalize(); | ||
beatTable.getKeyCollection().forEach(k -> assertDiagonalElementIsZero(k)); | ||
} | ||
|
||
private void assertDiagonalElementIsZero(final String key) { | ||
Pair element = beatTable.getElement(key, key); | ||
assertEquals(new Pair(0, 0), element); | ||
} | ||
} |