Skip to content

Instantly share code, notes, and snippets.

@beatgammit
Created February 25, 2013 20:12
Show Gist options
  • Save beatgammit/5032853 to your computer and use it in GitHub Desktop.
Save beatgammit/5032853 to your computer and use it in GitHub Desktop.
Blackbox Testing
package Model;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
/**
* Does a simple boundary value test on HyPeerWeb.
* This checks three conditions:
* 1. Edges (0 and last node)
* 2. Lower than boundaries (-1 and last node - 1)
* - 1st case should be error
* 3. Higher than boundaries (1 and last node + 1)
* - second case should be error
*
* @author T. Jameson Little
*
*/
public class NodeBoundaryValueTest {
private final int NUM_NODES = 20;
private HyPeerWeb hypeerweb = HyPeerWeb.getSingleton();
private List<Node> nodes = new ArrayList<Node>();
/**
* Setup HyPeerWeb.
*/
@Before
public void executeBeforeEveryTest() {
nodes.clear();
hypeerweb.clear();
Node zero = new Node(0);
hypeerweb.addToHyPeerWeb(zero, null);
nodes.add(zero);
for (int i = 1; i < NUM_NODES; i++) {
Node node = new Node(0);
nodes.add(node);
hypeerweb.addToHyPeerWeb(node, zero);
}
}
/**
* Test the boundaries (both should exist)
*/
@Test
public void testLegitBoundary() {
assertEquals(hypeerweb.getNode(0), nodes.get(0));
assertEquals(hypeerweb.getNode(NUM_NODES-1), nodes.get(NUM_NODES-1));
}
/**
* Test one below each boundary (lower boundary should return error).
*/
@Test
public void testBelowBoundary() {
assertEquals(hypeerweb.getNode(-1), Node.NULL_NODE);
assertEquals(hypeerweb.getNode(NUM_NODES-2), nodes.get(NUM_NODES-2));
}
/**
* Test above each boundary (upper boundary should return error).
*/
@Test
public void testAboveBoundary() {
assertEquals(hypeerweb.getNode(1), nodes.get(1));
assertEquals(hypeerweb.getNode(NUM_NODES), Node.NULL_NODE);
}
}
package Model;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
/**
* Does a simple equivalence partition test on HyPeerWeb.
* This checks three conditions:
* 1. One valid condition (between 0 and last node inclusive)
* 2. Lower than lower boundary (any value below 0)
* 3. Higher than upper boundaries (any value above last node)
*
* @author T. Jameson Little
*
*/
public class NodeEquivalencePartitionTest {
private final int NUM_NODES = 20;
private HyPeerWeb hypeerweb = HyPeerWeb.getSingleton();
private List<Node> nodes = new ArrayList<Node>();
/**
* Setup HyPeerWeb.
*/
@Before
public void executeBeforeEveryTest() {
nodes.clear();
hypeerweb.clear();
Node zero = new Node(0);
hypeerweb.addToHyPeerWeb(zero, null);
nodes.add(zero);
for (int i = 1; i < NUM_NODES; i++) {
Node node = new Node(0);
nodes.add(node);
hypeerweb.addToHyPeerWeb(node, zero);
}
}
/**
* Test a valid random node.
*/
@Test
public void testLegit() {
int id = (int)(Math.random()*NUM_NODES);
assertEquals(hypeerweb.getNode(id), nodes.get(id));
}
/**
* Test below lower boundary (should return error).
*/
@Test
public void testBelowLowerBoundary() {
int id = -(int)(Math.random()*Integer.MAX_VALUE);
assertEquals(hypeerweb.getNode(id), Node.NULL_NODE);
}
/**
* Test above upper boundary (should return error).
*/
@Test
public void testAboveUpperBoundary() {
int id = (int)(Math.random()*(Integer.MAX_VALUE-NUM_NODES)) + NUM_NODES;
assertEquals(hypeerweb.getNode(id), Node.NULL_NODE);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment