Ejemplo n.º 1
0
 @Test
 public void testInsert() {
   Queue<Integer> q = new Queue<Integer>();
   q.insert(1);
   q.insert(2);
   assertFalse(q.isEmpty());
 }
Ejemplo n.º 2
0
    @Test
    public void testGetQueueItems() throws IOException, Exception{
        ListView view1 = listView("view1");
        view1.filterQueue = true;
        ListView view2 = listView("view2");
        view2.filterQueue = true;

        FreeStyleProject inView1 = j.createFreeStyleProject("in-view1");
        inView1.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view1.add(inView1);

        MatrixProject inView2 = j.createMatrixProject("in-view2");
        inView2.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view2.add(inView2);

        FreeStyleProject notInView = j.createFreeStyleProject("not-in-view");
        notInView.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));

        FreeStyleProject inBothViews = j.createFreeStyleProject("in-both-views");
        inBothViews.setAssignedLabel(j.jenkins.getLabelAtom("without-any-slave"));
        view1.add(inBothViews);
        view2.add(inBothViews);

        Queue.getInstance().schedule(notInView, 0);
        Queue.getInstance().schedule(inView1, 0);
        Queue.getInstance().schedule(inView2, 0);
        Queue.getInstance().schedule(inBothViews, 0);

        Thread.sleep(1000);

        assertContainsItems(view1, inView1, inBothViews);
        assertNotContainsItems(view1, notInView, inView2);
        assertContainsItems(view2, inView2, inBothViews);
        assertNotContainsItems(view2, notInView, inView1);
    }
Ejemplo n.º 3
0
 @Test
 public void testIsEmpty() {
   Queue<Integer> q = new Queue<Integer>();
   q.insert(1);
   assertFalse(q.isEmpty());
   q.remove();
   assertTrue(q.isEmpty());
 }
Ejemplo n.º 4
0
  @Test
  public void TestPushPop() {
    int[] values = new int[] {0, 1, 2, 3, 4, 5};
    Queue<Integer> q = new Queue<Integer>();
    for (int i = 0; i < values.length; i++) {
      q.push(values[i]);
    }

    for (int i = 0; i < values.length; i++) {
      assertEquals(values[i], (int) q.pop());
    }
  }
Ejemplo n.º 5
0
 @Test
 public void testIterator() {
   Queue<Integer> q = new Queue<Integer>();
   q.insert(1);
   q.insert(2);
   Iterator<Integer> x = q.iterator();
   assertTrue(x.hasNext());
   x.next();
   assertTrue(x.hasNext());
   x.next();
   assertFalse(x.hasNext());
 }
  @Test
  public void sizeTest() {
    // When the stack empty...
    assertEquals(0, queue.size());

    // Adding some elements...
    queue.enqueue(1);
    assertEquals(1, queue.size());

    // Testing it backwards...
    queue.dequeue();
    assertEquals(0, queue.size());
  }
  @Test
  public void isEmptyTest() {
    // When the stack empty...
    assertEquals(true, queue.isEmpty());

    // Adding some elements...
    queue.enqueue(1);
    assertEquals(false, queue.isEmpty());

    // Testing it backwards...
    queue.dequeue();
    assertEquals(true, queue.isEmpty());
  }
Ejemplo n.º 8
0
 private void assertNotContainsItems(View view, Task... items) {
     for (Task job: items) {
         assertFalse(
                 "Queued items for " + view.getDisplayName() + " should not contain " + job.getDisplayName(),
                 view.getQueueItems().contains(Queue.getInstance().getItem(job))
         );
     }
 }
  @Test
  public void dequeueTest() {
    // When the stack empty...
    try {
      queue.dequeue();
      fail("A IllegalStateException should be thrown.");
    } catch (IllegalStateException e) {
    }

    // Adding some elements...
    queue.enqueue(1);
    queue.enqueue(2);
    queue.enqueue(3);
    assertEquals(1, queue.dequeue());

    // Checking that this method removes something.
    assertEquals(2, queue.dequeue());
  }
Ejemplo n.º 10
0
  @Test
  public void TestPushPopMixed() {
    int[] values = new int[] {0, 1, 2, 3, 4, 5, 6, 7};
    Queue<Integer> q = new Queue<Integer>();
    final int firstIteration = 2;
    for (int i = 0; i < values.length / 2; i++) {
      q.push(values[i]);
    }

    for (int i = 0; i < firstIteration; i++) {
      assertEquals(values[i], (int) q.pop());
    }

    for (int i = values.length / 2; i < values.length; i++) {
      q.push(values[i]);
    }

    for (int i = firstIteration; i < values.length; i++) {
      assertEquals(values[i], (int) q.pop());
    }
  }