Skip to content
Permalink
Browse files

Minor changes

  • Loading branch information...
No3x committed Jul 24, 2019
1 parent f41861d commit 9bfd52233a598f61d10a7b47004c54f02a01959e
@@ -5,9 +5,9 @@
*/
public class Clock {

private final de.no3x.countercascade.LinkedModCounter hours = new de.no3x.countercascade.LinkedModCounter(24, null);
private final de.no3x.countercascade.LinkedModCounter minutes = new de.no3x.countercascade.LinkedModCounter(60, hours);
private final de.no3x.countercascade.LinkedModCounter seconds = new de.no3x.countercascade.LinkedModCounter(60, minutes);
private final LinkedModCounter hours = new LinkedModCounter(24, null);
private final LinkedModCounter minutes = new LinkedModCounter(60, hours);
private final LinkedModCounter seconds = new LinkedModCounter(60, minutes);

public int getSeconds() {
return seconds.getCount();
@@ -19,4 +19,5 @@ public int increment() {
}
return 0;
}

}
@@ -17,8 +17,7 @@ public ModCounter(int mod) {

@Override
public int increment() {
set( super.increment() % mod);
return 0;
return set( super.increment() % mod);
}

@Override
@@ -2,6 +2,9 @@

import org.junit.Test;

import java.util.concurrent.TimeUnit;
import java.util.function.Function;

import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertThat;

@@ -33,4 +36,20 @@ public void decrement() throws Exception {
modCounter.decrement();
assertThat( modCounter.getCount(), is(0) );
}

@Test
public void discreteTests() throws Exception {
Function<Integer, Integer> f = t -> ( (int) Math.floor( (t)/60.)) % 60;
for (int i = 0; i <= TimeUnit.MINUTES.toSeconds(1)-1; i++) {
System.out.println(f.apply(i));
assertThat( f.apply(i), is(0));
}

for (int i = 60; i <= TimeUnit.MINUTES.toSeconds(2)-1; i++) {
assertThat( f.apply(i), is(1));
}

assertThat( f.apply( (int) TimeUnit.MINUTES.toSeconds(1)), is(1));
assertThat( f.apply( (int) TimeUnit.MINUTES.toSeconds(2)), is(2));
}
}

0 comments on commit 9bfd522

Please sign in to comment.
You can’t perform that action at this time.