示例#1
0
 /** Test of addElement method, of class Set. */
 @Test
 public void testAddElement() {
   Set<String> set = new Set<String>();
   set.addElement("m");
   set.addElement("h");
   set.addElement("m");
   assertTrue(set.elementExists("m"));
   assertFalse(set.elementExists("n"));
 }
示例#2
0
 /** Test of intersection method, of class Set. */
 @Test
 public void testIntersection() {
   Set<Integer> set1 = new Set<Integer>();
   Set<Integer> set2 = new Set<Integer>();
   set1.addElement(1);
   set1.addElement(2);
   set2.addElement(2);
   set2.addElement(3);
   assertTrue(set1.intersection(set2).elementExists(2));
   assertFalse(set1.intersection(set2).elementExists(3));
 }
示例#3
0
 /** Test of association method, of class Set. */
 @Test
 public void testAssociation() {
   Set<Integer> set1 = new Set<Integer>();
   Set<Integer> set2 = new Set<Integer>();
   set1.addElement(1);
   set1.addElement(2);
   set2.addElement(2);
   set2.addElement(3);
   assertTrue(set1.association(set2).elementExists(1));
   assertTrue(set1.association(set2).elementExists(2));
   assertTrue(set1.association(set2).elementExists(3));
 }
  /** Test of intersect method, of class Set. */
  @Test
  public void testIntersect() {
    Set<Integer> otherSet = new Set<>();
    otherSet.addElement(1349);
    otherSet.addElement(138);
    otherSet.addElement(1349);
    otherSet.addElement(16);

    String res = "";
    Set<Integer> resultSet = set.intersect(otherSet);
    for (Integer i : resultSet.toUniqueList()) {
      res += i + " ";
    }
    assertEquals("16 138 ", res);
  }
  /** Test of union method, of class Set. */
  @Test
  public void testUnion() {
    Set<Integer> otherSet = new Set<>();
    otherSet.addElement(1349);
    otherSet.addElement(138);
    otherSet.addElement(1349);
    otherSet.addElement(12);

    Set<Integer> result = set.union(otherSet);
    String res = "";
    for (Integer i : result.toUniqueList()) {
      System.out.format("%d ", i);
    }

    System.out.println(res);
  }
示例#6
0
 /** Test of isEmpty method, of class Set. */
 @Test
 public void testIsEmpty() {
   Set<Integer> set = new Set<Integer>();
   assertTrue(set.isEmpty());
   set.addElement(0);
   assertFalse(set.isEmpty());
 }
示例#7
0
 /** Test of elementExists method, of class Set. */
 @Test
 public void testElementExists() {
   Set<Integer> set = new Set<Integer>();
   assertFalse(set.elementExists(1));
   set.addElement(1);
   assertTrue(set.elementExists(1));
 }
示例#8
0
 /** Test of deleteElement method, of class Set. */
 @Test(expected = ElementNotFoundException.class)
 public void testDeleteElement() throws Exception {
   Set<Integer> set = new Set<Integer>();
   set.deleteElement(3);
   set.addElement(1);
   set.addElement(4);
   set.deleteElement(1);
   assertFalse(set.elementExists(1));
 }