From 8510eaee93a4f5e5959dbae59cf7678345e4b204 Mon Sep 17 00:00:00 2001 From: samskivert Date: Tue, 14 Jul 2009 17:53:21 +0000 Subject: [PATCH] Improved ArrayIntSet unit tests. Updated to JUnit4. git-svn-id: https://samskivert.googlecode.com/svn/trunk@2594 6335cc39-0255-0410-8fd6-9bcaacd3b74c --- .../util/tests/ArrayIntSetTest.java | 55 +++++++++++-------- 1 file changed, 31 insertions(+), 24 deletions(-) diff --git a/src/java/com/samskivert/util/tests/ArrayIntSetTest.java b/src/java/com/samskivert/util/tests/ArrayIntSetTest.java index 18beafa5..1b8eefa0 100644 --- a/src/java/com/samskivert/util/tests/ArrayIntSetTest.java +++ b/src/java/com/samskivert/util/tests/ArrayIntSetTest.java @@ -21,31 +21,49 @@ package com.samskivert.util.tests; import java.util.Arrays; +import java.util.HashSet; import java.util.Random; +import java.util.Set; +import java.util.TreeSet; -import junit.framework.Test; -import junit.framework.TestCase; +import org.junit.*; +import static org.junit.Assert.*; import com.samskivert.util.ArrayIntSet; -public class ArrayIntSetTest extends TestCase +public class ArrayIntSetTest { - public ArrayIntSetTest () - { - super(ArrayIntSetTest.class.getName()); - } - - @Override - public void runTest () + @Test + public void testAdd () { ArrayIntSet set = new ArrayIntSet(); set.add(new int[] { 3, 5, 5, 9, 5, 7, 1 }); - int[] values = { 1, 3, 5, 7, 9 }; - int[] setvals = set.toIntArray(); + assertTrue("values equal", Arrays.equals(values, set.toIntArray())); + } - assertTrue("values equal", Arrays.equals(values, setvals)); + @Test + public void testConstruct () + { + int[] values = { 11, 3, 20, 6, 16, 15, 24, 23, 21, 10, 4, 19, 13, 25, 22, 18 }; + ArrayIntSet set1 = new ArrayIntSet(values); + ArrayIntSet set2 = new ArrayIntSet(); + set2.add(values); + assertTrue(set1.equals(set2)); + } + @Test + public void testIterate () + { + ArrayIntSet set = new ArrayIntSet(new int[] { 3, 5, 5, 9, 5, 7, 1 }); + Set jset = new TreeSet(); + jset.addAll(set); + assertTrue(jset.equals(set)); + } + + @Test + public void testOps () + { ArrayIntSet set1 = new ArrayIntSet(); set1.add(new int[] { 1, 2, 3, 5, 7, 12, 19, 35 }); ArrayIntSet set2 = new ArrayIntSet(); @@ -91,15 +109,4 @@ public class ArrayIntSetTest extends TestCase assertTrue("random intersection", s1.equals(s3)); } } - - public static Test suite () - { - return new ArrayIntSetTest(); - } - - public static void main (String[] args) - { - ArrayIntSetTest test = new ArrayIntSetTest(); - test.runTest(); - } }