From d474aea7e0b67ca3e04a07bad68102020e56abf8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Zurcher?= Date: Mon, 11 Jan 2016 16:00:42 +0100 Subject: tests: add stuff for IterableArray --- core/test/ch/asynk/rustanddust/Util.java | 74 ++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 core/test/ch/asynk/rustanddust/Util.java diff --git a/core/test/ch/asynk/rustanddust/Util.java b/core/test/ch/asynk/rustanddust/Util.java new file mode 100644 index 0000000..5ed7b13 --- /dev/null +++ b/core/test/ch/asynk/rustanddust/Util.java @@ -0,0 +1,74 @@ +package ch.asynk.rustanddust; + +import org.junit.Test; + +import ch.asynk.rustanddust.engine.util.IterableArray; + +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; + +public class Util +{ + @Test + public void testArray() + { + IterableArray a = new IterableArray(3); + assertTrue(a.isEmpty()); + assertTrue(a.size() == 0); + a.add(new Object()); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 1); + a.add(new Object()); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 2); + Object o = new Object(); + assertFalse(a.contains(o)); + a.add(o); + assertTrue(a.contains(o)); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 3); + a.add(new Object()); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 4); + + assertTrue(a.get(2) == o); + + a.clear(); + assertTrue(a.isEmpty()); + assertTrue(a.size() == 0); + + a.add(new Object()); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 1); + a.add(new Object()); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 2); + assertFalse(a.contains(o)); + a.add(o); + assertTrue(a.contains(o)); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 3); + a.add(new Object()); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 4); + + assertTrue(a.get(2) == o); + a.add(o); + assertTrue(a.contains(o)); + + assertFalse(a.isEmpty()); + assertTrue(a.size() == 5); + assertTrue(a.remove(o)); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 4); + assertTrue(a.remove(o)); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 3); + assertFalse(a.remove(o)); + + assertNotNull(a.remove(1)); + assertFalse(a.isEmpty()); + assertTrue(a.size() == 2); + } +} -- cgit v1.1-2-g2b99