Skip to content

Instantly share code, notes, and snippets.

@dschinkel
Last active March 10, 2017 21:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dschinkel/68723984b4b4d43550ab1b3d2e5e9715 to your computer and use it in GitHub Desktop.
Save dschinkel/68723984b4b4d43550ab1b3d2e5e9715 to your computer and use it in GitHub Desktop.
First few tests
import org.junit.Test;
import static junit.framework.TestCase.*;
/* requirements: Implement the following behavior:
set() - creation with or without specified size
add()
clear()
contains()
isEmpty()
iterator()
remove()
size()
*/
public class SetTest {
@Test
public void canCreateAnEmptySet(){
Set set = createSet();
assertTrue(set.isEmpty());
}
@Test
public void anEmptySetHasNoSize(){
Set set = createSet();
assertEquals(0, set.size());
}
@Test
public void canCreateSetForSpecificSize() {
Set set = createSet(4);
assertEquals(4, set.size());
}
@Test
public void setsWithSizeGreaterThanZeroShouldNotBeEmpty() {
Set set = createSet(4);
assertFalse(set.isEmpty());
}
@Test
public void canClearASet() {
Set set = createSet(4);
set.clear();
assertSame(0, set.size());
}
@Test
public void clearingASetEmptiesTheSet() {
Set set = createSet(4);
set.clear();
assertTrue(set.isEmpty());
}
private Set createSet() {
return new Set();
}
private Set createSet(int size) {
return new Set(size);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment