Commit 2a67fb19 authored by Colin DAMON's avatar Colin DAMON

Puzzles resolution

parent 6079210f
package-java-puzzles:
variables:
PROJECT_FOLDER: "java-puzzles"
extends: .java
extends: .java-no-jacoco
only:
refs:
- master
......
......@@ -11,8 +11,9 @@ public class PlayingWithBigDecimal {
public void roundingSubstract() {
BigDecimal a = new BigDecimal(2.00);
BigDecimal b = new BigDecimal(0.99);
// assertThat(a.subtract(b).toString()).isEqualTo("1");
// assertThat(a.subtract(b).toString()).isEqualTo("1.01");
// assertThat(a.subtract(b).toString()).isEqualTo("1.0100000000000000088817841970012523233890533447265625");
// assertThat(a.subtract(b).toString()).isEqualTo("1");
// assertThat(a.subtract(b).toString()).isEqualTo("1.01");
assertThat(a.subtract(b).toString()).isEqualTo("1.0100000000000000088817841970012523233890533447265625");
}
}
......@@ -9,7 +9,7 @@ public class PlayingWithFinally {
@Test
public void playingWithReturn() {
// assertThat(finallyReturn()).isEqualTo(42);
// assertThat(finallyReturn()).isEqualTo(1337);
assertThat(finallyReturn()).isEqualTo(1337);
}
@SuppressWarnings("finally")
......@@ -24,9 +24,7 @@ public class PlayingWithFinally {
@Test
public void playingWithThrow() {
// assertThat(finallyThrow()).isEqualTo(42);
// assertThatThrownBy(() -> finallyThrow())
// .isInstanceOf(IllegalArgumentException.class)
// .hasMessageContaining("Damned");
assertThatThrownBy(() -> finallyThrow()).isInstanceOf(IllegalArgumentException.class).hasMessageContaining("Damned");
}
@SuppressWarnings("finally")
......
......@@ -13,9 +13,9 @@ public class PlayingWithInstanciations {
long start = System.currentTimeMillis();
// assertThat(start).isLessThanOrEqualTo(instanciation);
// assertThat(start).isGreaterThan(instanciation);
assertThat(start).isGreaterThan(instanciation);
MyPrivateClass.doStuff();
// assertThat(start).isLessThanOrEqualTo(MyPrivateClass.instanciation);
assertThat(start).isLessThanOrEqualTo(MyPrivateClass.instanciation);
// assertThat(start).isGreaterThan(MyPrivateClass.instanciation);
}
......
......@@ -10,7 +10,8 @@ public class PlayingWithInteger {
public void comparingUniversaleAnswerIntegerReferences() {
Integer a = 42;
Integer b = 42;
// assertThat(a).isSameAs(b);
assertThat(a).isSameAs(b);
// assertThat(a).isNotSameAs(b);
}
......@@ -18,14 +19,14 @@ public class PlayingWithInteger {
public void comparingDevilIntegerReferences() {
Integer a = 666;
Integer b = 666;
// assertThat(a).isSameAs(b);
// assertThat(a).isNotSameAs(b);
// assertThat(a).isSameAs(b);
assertThat(a).isNotSameAs(b);
}
@Test
public void checkingAbsoluteValue() {
// assertThat(Math.abs(Integer.MIN_VALUE)).isEqualTo(Integer.MAX_VALUE);
// assertThat(Math.abs(Integer.MIN_VALUE))
// .isEqualTo(Integer.MIN_VALUE);
assertThat(Math.abs(Integer.MIN_VALUE)).isEqualTo(Integer.MIN_VALUE);
}
}
......@@ -8,20 +8,19 @@ public class PlayingWithString {
@Test
public void playingWithReferences() {
// assertThat("coucou").isSameAs("coucou");
assertThat("coucou").isSameAs("coucou");
// assertThat("coucou").isNotSameAs("coucou");
}
@Test
public void playingWithStringObjectsReferences() {
// assertThat(new String("coucou")).isSameAs(new String("coucou"));
// assertThat(new String("coucou")).isNotSameAs(new String("coucou"));
assertThat(new String("coucou")).isNotSameAs(new String("coucou"));
}
@Test
public void playingWithIntern() {
// assertThat(new String("coucou").intern())
// .isSameAs(new String("coucou").intern());
assertThat(new String("coucou").intern()).isSameAs(new String("coucou").intern());
// assertThat(new String("coucou").intern()).isNotSameAs(new
// String("coucou").intern());
}
......
......@@ -26,11 +26,11 @@ public class PlayingWithThreads {
Set<Integer> days = Collections.newSetFromMap(new ConcurrentHashMap<>());
ExecutorService executor = Executors.newFixedThreadPool(10);
SimpleDateFormat format = new SimpleDateFormat("dd");
AtomicInteger counter = new AtomicInteger(1);
for (int i = 1; i < 32; ++i) {
executor.submit(
() -> {
SimpleDateFormat format = new SimpleDateFormat("dd");
Date date = new GregorianCalendar(2018, Calendar.JANUARY, counter.getAndIncrement()).getTime();
days.add(Integer.parseInt(format.format(date)));
}
......@@ -39,8 +39,9 @@ public class PlayingWithThreads {
executor.shutdown();
executor.awaitTermination(3, TimeUnit.SECONDS);
// assertThat(days).hasSize(31);
// assertThat(days.size()).isLessThan(31);
// assertThat(days).hasSize(31);
assertThat(days.size()).isLessThan(31);
}
@Test
......@@ -61,7 +62,7 @@ public class PlayingWithThreads {
threadDoneFlag = true;
Thread.sleep(50);
// assertThat(threadStopped.get()).isFalse();
assertThat(threadStopped.get()).isFalse();
// assertThat(threadStopped.get()).isTrue();
}
......@@ -85,8 +86,9 @@ public class PlayingWithThreads {
threadDoneFlag = true;
Thread.sleep(50);
// assertThat(threadStopped.get()).isFalse();
// assertThat(threadStopped.get()).isTrue();
// assertThat(threadStopped.get()).isFalse();
assertThat(threadStopped.get()).isTrue();
}
@Test
......@@ -107,7 +109,8 @@ public class PlayingWithThreads {
threadDoneAtomicFlag.set(true);
Thread.sleep(50);
// assertThat(threadStopped.get()).isFalse();
// assertThat(threadStopped.get()).isTrue();
// assertThat(threadStopped.get()).isFalse();
assertThat(threadStopped.get()).isTrue();
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment