lots of exercises in java... from https://github.com/exercism/java

SimpleLinkedListTest.java 2.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. import org.junit.Ignore;
  2. import org.junit.Test;
  3. import java.util.NoSuchElementException;
  4. import static org.hamcrest.CoreMatchers.*;
  5. import static org.junit.Assert.*;
  6. public class SimpleLinkedListTest {
  7. @Test
  8. public void aNewListIsEmpty() {
  9. SimpleLinkedList list = new SimpleLinkedList();
  10. assertThat(list.size(), is(0));
  11. }
  12. @Ignore
  13. @Test
  14. public void canCreateFromArray() {
  15. Integer[] values = new Integer[]{1, 2, 3};
  16. SimpleLinkedList list = new SimpleLinkedList(values);
  17. assertThat(list.size(), is(3));
  18. }
  19. @Ignore
  20. @Test(expected = NoSuchElementException.class)
  21. public void popOnEmptyListWillThrow() {
  22. SimpleLinkedList list = new SimpleLinkedList();
  23. list.pop();
  24. }
  25. @Ignore
  26. @Test
  27. public void popReturnsLastAddedElement() {
  28. SimpleLinkedList list = new SimpleLinkedList();
  29. list.push(9);
  30. list.push(8);
  31. assertThat(list.size(), is(2));
  32. assertThat(list.pop(), is(8));
  33. assertThat(list.pop(), is(9));
  34. assertThat(list.size(), is(0));
  35. }
  36. @Ignore
  37. @Test
  38. public void reverseReversesList() {
  39. SimpleLinkedList list = new SimpleLinkedList();
  40. list.push(9);
  41. list.push(8);
  42. list.push(7);
  43. list.push(6);
  44. list.push(5);
  45. list.reverse();
  46. assertThat(list.pop(), is(9));
  47. assertThat(list.pop(), is(8));
  48. assertThat(list.pop(), is(7));
  49. assertThat(list.pop(), is(6));
  50. assertThat(list.pop(), is(5));
  51. }
  52. @Ignore
  53. @Test
  54. public void canReturnListAsArray() {
  55. SimpleLinkedList list = new SimpleLinkedList();
  56. list.push(9);
  57. list.push(8);
  58. list.push(7);
  59. list.push(6);
  60. list.push(5);
  61. Integer[] expected = {5, 6, 7, 8, 9};
  62. assertEquals(list.asArray(Integer.class), expected);
  63. }
  64. @Ignore
  65. @Test
  66. public void canReturnEmptyListAsEmptyArray() {
  67. SimpleLinkedList list = new SimpleLinkedList();
  68. Object[] expected = {};
  69. assertEquals(list.asArray(Object.class), expected);
  70. }
  71. }