Created
November 29, 2011 04:10
-
-
Save blkbsstt/1403372 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package cs515.hw3; | |
public class OneWayListTest | |
{ | |
public static void main(String[] args) | |
{ | |
// Creating a new OneWayList | |
OneWayList<Integer> list = new OneWayList<Integer>(); | |
// On creation, both lists should be empty | |
assert list.LeftSize() == 0 && list.RightSize() == 0 : "After creation, both sides should be empty"; | |
// Populating the list with 0 - 9 | |
for(int i = 0; i < 10; i++) | |
{ | |
list.AddRight(i); | |
list.Advance(); | |
} | |
// The iterated over elements should all be in the left side | |
assert list.LeftSize() == 10 : "After adding elements, all should be on left side"; | |
assert list.RightSize() == 0 : "After adding elements, no elements should be on right side"; | |
list.MoveToStart(); | |
assert list.LeftSize() == 0 : "After moving to start, no elements should be on left side"; | |
assert list.RightSize() == 10 : "After moving to start, all elements should be on right side"; | |
// Removing | |
for(int i = 0; i < 9; i++) | |
{ | |
assert list.RemoveRight() == i : "RemoveRight returns the elements in order"; | |
} | |
assert list.RightFront() == list.RemoveRight() : "RightFront() returns the value of the next RemoveRight()"; | |
for(int i = 0; i < 10; i++) | |
{ | |
list.AddRight(i); | |
list.Advance(); | |
} | |
OneWayList<Integer> other = new OneWayList<Integer>(); | |
for(int i = 10; i < 20; i++) | |
{ | |
other.AddRight(i); | |
other.Advance(); | |
} | |
other.MoveToStart(); | |
other.SwapRights(list); | |
// other should be empty | |
assert other.LeftSize() == 0 && other.RightSize() == 0; | |
assert list.LeftSize() == 10 && list.RightSize() == 10; | |
for(int i = 10; i < 20; i++) | |
{ | |
assert list.RemoveRight() == i; | |
} | |
System.out.println("All tests passed!"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment