From d9fcd8225ba5cdba8cbbe57fc05b67dfcf083be9 Mon Sep 17 00:00:00 2001 From: Carolynn Vansant Date: Sat, 10 Mar 2018 19:42:09 -0500 Subject: [PATCH 1/7] first commit --- src/main/java/Pair/Arrays.java | 4 +- src/main/java/StackArray/GenericStack.java | 19 ++++ src/main/java/StackArray/ObjectStack.java | 16 +++ src/main/java/StackArrayList/Stack.java | 19 +++- src/main/java/Table/Table.java | 30 ++++++ .../java/StackArray/GenericStackTest.java | 82 +++++++------- src/test/java/StackArray/ObjectStackTest.java | 78 +++++++------- src/test/java/StackArrayList/StackTest.java | 90 ++++++++-------- src/test/java/Table/TableTest.java | 100 +++++++++--------- 9 files changed, 260 insertions(+), 178 deletions(-) diff --git a/src/main/java/Pair/Arrays.java b/src/main/java/Pair/Arrays.java index 5bdf780..07bf207 100644 --- a/src/main/java/Pair/Arrays.java +++ b/src/main/java/Pair/Arrays.java @@ -10,7 +10,7 @@ * A max method that returns the largest item in the arraylist * And a minmax method that returns a pair containing the largest and smallest items from the array list */ -public class Arrays { +/*public class Arrays { public static <___> Pair firstLast(ArrayList<___> a) { } -} +}*/ diff --git a/src/main/java/StackArray/GenericStack.java b/src/main/java/StackArray/GenericStack.java index d84c4db..d3a7438 100644 --- a/src/main/java/StackArray/GenericStack.java +++ b/src/main/java/StackArray/GenericStack.java @@ -1,6 +1,8 @@ package StackArray; + import java.util.Arrays; +import java.lang.*; /** * Expand the ArrayList implementation of stack here to use an E[] array. Still implement push, pop, and isEmpty. @@ -11,5 +13,22 @@ public class GenericStack { private E[] elements; public GenericStack() { + this.elements = (E[]) new Object[0]; + } + + public void push(E object){ + elements = Arrays.copyOf(elements, elements.length+1); + elements[elements.length-1] = object; + } + + public E pop(){ + E object = elements[elements.length-1]; + elements = Arrays.copyOf(elements, elements.length-1); + return object; + } + + public boolean isEmpty(){ + if(elements.length == 0) return true; + else return false; } } diff --git a/src/main/java/StackArray/ObjectStack.java b/src/main/java/StackArray/ObjectStack.java index 1124698..89c1012 100644 --- a/src/main/java/StackArray/ObjectStack.java +++ b/src/main/java/StackArray/ObjectStack.java @@ -11,6 +11,22 @@ public class ObjectStack { private Object[] elements; public ObjectStack() { + this.elements = new Object[0]; + } + + public void push(Object item){ + elements = Arrays.copyOf(elements, elements.length+1); + elements[elements.length-1] = item; + } + + public Object pop(){ + Object item = elements[elements.length-1]; + elements = Arrays.copyOf(elements, elements.length-1); + return item; + } + public boolean isEmpty(){ + if(elements.length == 0) return true; + else return false; } } diff --git a/src/main/java/StackArrayList/Stack.java b/src/main/java/StackArrayList/Stack.java index 0338de3..9bdff0d 100644 --- a/src/main/java/StackArrayList/Stack.java +++ b/src/main/java/StackArrayList/Stack.java @@ -7,10 +7,27 @@ * If you pop on an empty stack, throw an IndexOutOfBoundsException. */ public class Stack { - private ArrayList elements; + private ArrayList elements; public Stack(){ + this.elements = new ArrayList(); + } + + public ArrayList getElements() { + return elements; + } + + public void push(E item){ + elements.add(item); + } + + public E pop(){ + return elements.remove(elements.size()-1); + } + public boolean isEmpty(){ + return elements.isEmpty(); } + } diff --git a/src/main/java/Table/Table.java b/src/main/java/Table/Table.java index 5ccce23..8bafdf3 100644 --- a/src/main/java/Table/Table.java +++ b/src/main/java/Table/Table.java @@ -13,5 +13,35 @@ public class Table { private ArrayList entries; public Table() { + this.entries = new ArrayList>(); + } + + public Entry get(K key){ + Entry enter = null; + for(int i = 0; i stack = new GenericStack<>(); -// -// // Assert that it is empty. -// Assert.assertEquals(true, stack.isEmpty()); -// // When we push something onto the stack -// stack.push("foobar"); -// // Then it shouldn't be empty -// Assert.assertEquals(false, stack.isEmpty()); -// } -// -// @Test -// public void testPushingAndPoppingOrder() throws Exception { -// // Given an empty stack -// GenericStack stack = new GenericStack<>(); -// // When we push two elements on it -// stack.push("foo"); -// stack.push("bar"); -// // Then we should see them returned in the correct order -// Assert.assertEquals("bar", stack.pop()); -// Assert.assertEquals("foo", stack.pop()); -// } -// -// @Test(expected = IndexOutOfBoundsException.class) -// public void testPopFirst() throws Exception { -// // Given an empty stack -// GenericStack stack = new GenericStack<>(); -// // When it's popped -// stack.pop(); -// // Then we should get an exception -// } -// -//} \ No newline at end of file +package StackArray; + +import org.junit.Assert; +import org.junit.Test; + +public class GenericStackTest { + @Test + public void testPushingGrowsTheStack() throws Exception { + // Given an empty stack + GenericStack stack = new GenericStack<>(); + + // Assert that it is empty. + Assert.assertEquals(true, stack.isEmpty()); + // When we push something onto the stack + stack.push("foobar"); + // Then it shouldn't be empty + Assert.assertEquals(false, stack.isEmpty()); + } + + @Test + public void testPushingAndPoppingOrder() throws Exception { + // Given an empty stack + GenericStack stack = new GenericStack<>(); + // When we push two elements on it + stack.push("foo"); + stack.push("bar"); + // Then we should see them returned in the correct order + Assert.assertEquals("bar", stack.pop()); + Assert.assertEquals("foo", stack.pop()); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void testPopFirst() throws Exception { + // Given an empty stack + GenericStack stack = new GenericStack<>(); + // When it's popped + stack.pop(); + // Then we should get an exception + } + +} \ No newline at end of file diff --git a/src/test/java/StackArray/ObjectStackTest.java b/src/test/java/StackArray/ObjectStackTest.java index 9ec9615..2576f1b 100644 --- a/src/test/java/StackArray/ObjectStackTest.java +++ b/src/test/java/StackArray/ObjectStackTest.java @@ -1,39 +1,39 @@ -//package StackArray; -// -//import org.junit.Assert; -//import org.junit.Test; -// -//public class ObjectStackTest { -// @Test -// public void testPushingGrowsTheStack() throws Exception { -// // Given an empty stack -// ObjectStack stack = new ObjectStack<>(); -// // Assert that it is empty. -// Assert.assertEquals(true, stack.isEmpty()); -// // When we push something onto the stack -// stack.push("foobar"); -// // Then it shouldn't be empty -// Assert.assertEquals(false, stack.isEmpty()); -// } -// -// @Test -// public void testPushingAndPoppingOrder() throws Exception { -// // Given an empty stack -// ObjectStack stack = new ObjectStack<>(); -// // When we push two elements on it -// stack.push("foo"); -// stack.push("bar"); -// // Then we should see them returned in the correct order -// Assert.assertEquals("bar", stack.pop()); -// Assert.assertEquals("foo", stack.pop()); -// } -// -// @Test(expected = IndexOutOfBoundsException.class) -// public void testPopFirst() throws Exception { -// // Given an empty stack -// ObjectStack stack = new ObjectStack<>(); -// // When it's popped -// stack.pop(); -// // Then we should get an exception -// } -//} \ No newline at end of file +package StackArray; + +import org.junit.Assert; +import org.junit.Test; + +public class ObjectStackTest { + @Test + public void testPushingGrowsTheStack() throws Exception { + // Given an empty stack + ObjectStack stack = new ObjectStack<>(); + // Assert that it is empty. + Assert.assertEquals(true, stack.isEmpty()); + // When we push something onto the stack + stack.push("foobar"); + // Then it shouldn't be empty + Assert.assertEquals(false, stack.isEmpty()); + } + + @Test + public void testPushingAndPoppingOrder() throws Exception { + // Given an empty stack + ObjectStack stack = new ObjectStack<>(); + // When we push two elements on it + stack.push("foo"); + stack.push("bar"); + // Then we should see them returned in the correct order + Assert.assertEquals("bar", stack.pop()); + Assert.assertEquals("foo", stack.pop()); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void testPopFirst() throws Exception { + // Given an empty stack + ObjectStack stack = new ObjectStack<>(); + // When it's popped + stack.pop(); + // Then we should get an exception + } +} \ No newline at end of file diff --git a/src/test/java/StackArrayList/StackTest.java b/src/test/java/StackArrayList/StackTest.java index 0ce7cf0..00dc659 100644 --- a/src/test/java/StackArrayList/StackTest.java +++ b/src/test/java/StackArrayList/StackTest.java @@ -1,45 +1,45 @@ -//package StackArrayList; -// -//import org.junit.Test; -// -//import org.junit.Assert; -// -//public class StackTest { -// @Test -// public void testEmptyStackStopsBeingEmptyWhenAnItemIsAdded() throws Exception { -// // Given an empty stack -// Stack stack = new Stack<>(); -// // Assert that it starts empty -// Assert.assertEquals(true, stack.isEmpty()); -// // When an element gets pushed -// stack.push("foobar"); -// // Then the stack should not be empty. -// Assert.assertEquals(false, stack.isEmpty()); -// } -// -// @Test -// public void testTwoItemsPushedComeOutInCorrectOrder() throws Exception { -// // Given an empty stack -// Stack stack = new Stack<>(); -// -// //When two items are pushed -// stack.push("foo"); -// stack.push("bar"); -// -// // Then they should come off in reverse order. -// Assert.assertEquals("bar", stack.pop()); -// Assert.assertEquals("foo", stack.pop()); -// -// // And then the stack should be empty -// Assert.assertEquals(true, stack.isEmpty()); -// } -// -// @Test(expected = IndexOutOfBoundsException.class) -// public void testPopFirst() throws Exception { -// // Given an empty stack -// Stack stack = new Stack<>(); -// // Then it is popped -// stack.pop(); -// // We should get an exception -// } -//} \ No newline at end of file +package StackArrayList; + +import org.junit.Test; + +import org.junit.Assert; + +public class StackTest { + @Test + public void testEmptyStackStopsBeingEmptyWhenAnItemIsAdded() throws Exception { + // Given an empty stack + Stack stack = new Stack<>(); + // Assert that it starts empty + Assert.assertEquals(true, stack.isEmpty()); + // When an element gets pushed + stack.push("foobar"); + // Then the stack should not be empty. + Assert.assertEquals(false, stack.isEmpty()); + } + + @Test + public void testTwoItemsPushedComeOutInCorrectOrder() throws Exception { + // Given an empty stack + Stack stack = new Stack<>(); + + //When two items are pushed + stack.push("foo"); + stack.push("bar"); + + // Then they should come off in reverse order. + Assert.assertEquals("bar", stack.pop()); + Assert.assertEquals("foo", stack.pop()); + + // And then the stack should be empty + Assert.assertEquals(true, stack.isEmpty()); + } + + @Test(expected = IndexOutOfBoundsException.class) + public void testPopFirst() throws Exception { + // Given an empty stack + Stack stack = new Stack<>(); + // Then it is popped + stack.pop(); + // We should get an exception + } +} \ No newline at end of file diff --git a/src/test/java/Table/TableTest.java b/src/test/java/Table/TableTest.java index 15ac19c..8bebde6 100644 --- a/src/test/java/Table/TableTest.java +++ b/src/test/java/Table/TableTest.java @@ -1,50 +1,50 @@ -//package Table; -// -//import org.junit.Assert; -//import org.junit.Test; -// -//public class TableTest { -// @Test -// public void testGetWithoutAnItemReturnsNull() throws Exception { -// // Given an empty table -// Table table = new Table(); -// // When we try and get an item then it returns null -// Assert.assertEquals(table.get("foo"), null); -// } -// -// @Test -// public void testPutAnItemReturnsAndDoesNotDelete() throws Exception { -// //Given an empty table -// Table table = new Table(); -// // When we put an item in it -// table.put("foo", 1); -// // Then we should be able to get it's value -// Assert.assertEquals(table.get("foo"), new Integer(1)); -// // And then we should be able to get it again as it wasn't removed -// Assert.assertEquals(table.get("foo"), new Integer(1)); -// } -// -// @Test -// public void testOverwritingAnItem() throws Exception { -// //Given an empty table -// Table table = new Table(); -// // When we put an item in it -// table.put("foo", 1); -// // And we put a new value with the same key -// table.put("foo", 2); -// // Then we should get back the new value -// Assert.assertEquals(table.get("foo"), new Integer(2)); -// } -// -// @Test -// public void testRemoveAnItem() throws Exception { -// //Given an empty table -// Table table = new Table(); -// // When we put an item in it -// table.put("foo", 1); -// // And we remove that item -// table.remove("foo"); -// // Then we should get back null for that balue -// Assert.assertEquals(table.get("foo"), null); -// } -//} \ No newline at end of file +package Table; + +import org.junit.Assert; +import org.junit.Test; + +public class TableTest { + @Test + public void testGetWithoutAnItemReturnsNull() throws Exception { + // Given an empty table + Table table = new Table(); + // When we try and get an item then it returns null + Assert.assertEquals(table.get("foo"), null); + } + + @Test + public void testPutAnItemReturnsAndDoesNotDelete() throws Exception { + //Given an empty table + Table table = new Table(); + // When we put an item in it + table.put("foo", 1); + // Then we should be able to get it's value + Assert.assertEquals(table.get("foo"), new Integer(1)); + // And then we should be able to get it again as it wasn't removed + Assert.assertEquals(table.get("foo"), new Integer(1)); + } + + @Test + public void testOverwritingAnItem() throws Exception { + //Given an empty table + Table table = new Table(); + // When we put an item in it + table.put("foo", 1); + // And we put a new value with the same key + table.put("foo", 2); + // Then we should get back the new value + Assert.assertEquals(table.get("foo"), new Integer(2)); + } + + @Test + public void testRemoveAnItem() throws Exception { + //Given an empty table + Table table = new Table(); + // When we put an item in it + table.put("foo", 1); + // And we remove that item + table.remove("foo"); + // Then we should get back null for that balue + Assert.assertEquals(table.get("foo"), null); + } +} \ No newline at end of file From 2f9938d19e38e667eb958f17dc95a3dd8c84f683 Mon Sep 17 00:00:00 2001 From: Carolynn Vansant Date: Sat, 10 Mar 2018 23:54:32 -0500 Subject: [PATCH 2/7] about halfway there --- src/main/java/Table/Table.java | 51 +++++---- src/main/java/TableNested/TableNested.java | 67 ++++++++++++ src/test/java/Swap/SwapTest.java | 30 +++--- src/test/java/Table/TableTest.java | 1 + .../java/TableNested/TableNestedTest.java | 100 +++++++++--------- 5 files changed, 165 insertions(+), 84 deletions(-) diff --git a/src/main/java/Table/Table.java b/src/main/java/Table/Table.java index 8bafdf3..d572562 100644 --- a/src/main/java/Table/Table.java +++ b/src/main/java/Table/Table.java @@ -10,38 +10,51 @@ * Void return on `remove`. */ public class Table { - private ArrayList entries; + private ArrayList> entries; public Table() { - this.entries = new ArrayList>(); + this.entries = new ArrayList<>(); } - public Entry get(K key){ - Entry enter = null; - for(int i = 0; i> getEntries() { + return entries; + } + + public V get(K key) { + V value = null; + for (int i = 0; i < entries.size(); i++) { + K entryKey = entries.get(i).getKey(); + if (entryKey.equals(key)) { + value = entries.get(i).getValue(); } } - return enter; + return value; + } + public int size(){ + return entries.size(); } - public void put(K key, V value){ - for(int i = 0; i(key,value)); + //not sure why the for loop won't work but I'll come back to that later +/* for (int i = 0; i < entries.size(); i++) { + K entryKey = entries.get(i).getKey(); + if ((entries.get(i).getKey()).equals(key)) { + entries.set(i, new Entry<>(key,value)); + } else { + entries.add(i, new Entry<>(key,value)); } } +*/ } - public void remove(K key){ - for(int i = 0; i { + private ArrayList> entries; + + public TableNested() { + this.entries = new ArrayList<>(); + } + + public ArrayList> getEntries() { + return entries; + } + + public V get(K key) { + V value = null; + for (int i = 0; i < entries.size(); i++) { + K entryKey = entries.get(i).getKey(); + if (entryKey.equals(key)) { + value = entries.get(i).getValue(); + } + } + return value; + } + public int size(){ + return entries.size(); + } + + public void put(K key, V value) { + entries.add(new Entry<>(key,value)); + //not sure why the for loop won't work but I'll come back to that later +/* for (int i = 0; i < entries.size(); i++) { + if ((key.equals(entries.get(i).getKey()))){ + entries.set(i, new Entry<>(key,value)); + } else { + entries.add(i, new Entry<>(key,value)); + } + } +*/ + } + + public void remove(K key) { + for (int i = 0; i < entries.size(); i++) { + K entryKey = entries.get(i).getKey(); + if (entryKey.equals(key)) { + entries.remove(i); + } + } + } + + private class Entry { + private H key; + private R value; + + public Entry(H key, R value) { + this.key = key; + this.value = value; + } + + public H getKey() { + return key; + } + + public R getValue() { + return value; + } + + } + } diff --git a/src/test/java/Swap/SwapTest.java b/src/test/java/Swap/SwapTest.java index 2583b9d..4ee6f4b 100644 --- a/src/test/java/Swap/SwapTest.java +++ b/src/test/java/Swap/SwapTest.java @@ -1,16 +1,16 @@ package Swap; -// -//import org.junit.Assert; -//import org.junit.Test; -// -///** -// * Get the tests passing. -// */ -//public class SwapTest { -// @Test -// public void testSwap() throws Exception { -// Double[] result = Swap.swap(0,1, 1.5, 2,3); -// Double[] expected = {2.0, 1.5, 3.0}; -// Assert.assertArrayEquals(expected, result); -// } -//} \ No newline at end of file + +import org.junit.Assert; +import org.junit.Test; + +/** + * Get the tests passing. + */ +public class SwapTest { + @Test + public void testSwap() throws Exception { + Double[] result = Swap.swap(0,1, 1.5, 2.0, 3.0); + Double[] expected = {2.0, 1.5, 3.0}; + Assert.assertArrayEquals(expected, result); + } +} \ No newline at end of file diff --git a/src/test/java/Table/TableTest.java b/src/test/java/Table/TableTest.java index 8bebde6..5f01248 100644 --- a/src/test/java/Table/TableTest.java +++ b/src/test/java/Table/TableTest.java @@ -12,6 +12,7 @@ public void testGetWithoutAnItemReturnsNull() throws Exception { Assert.assertEquals(table.get("foo"), null); } + @Test public void testPutAnItemReturnsAndDoesNotDelete() throws Exception { //Given an empty table diff --git a/src/test/java/TableNested/TableNestedTest.java b/src/test/java/TableNested/TableNestedTest.java index 8432277..fdf12d5 100644 --- a/src/test/java/TableNested/TableNestedTest.java +++ b/src/test/java/TableNested/TableNestedTest.java @@ -1,50 +1,50 @@ -//package TableNested; -// -//import org.junit.Assert; -//import org.junit.Test; -// -//public class TableNestedTest { -// @Test -// public void testGetWithoutAnItemReturnsNull() throws Exception { -// // Given an empty table -// TableNested table = new TableNested(); -// // When we try and get an item then it returns null -// Assert.assertEquals(table.get("foo"), null); -// } -// -// @Test -// public void testPutAnItemReturnsAndDoesNotDelete() throws Exception { -// //Given an empty table -// TableNested table = new TableNested(); -// // When we put an item in it -// table.put("foo", 1); -// // Then we should be able to get it's value -// Assert.assertEquals(table.get("foo"), new Integer(1)); -// // And then we should be able to get it again as it wasn't removed -// Assert.assertEquals(table.get("foo"), new Integer(1)); -// } -// -// @Test -// public void testOverwritingAnItem() throws Exception { -// //Given an empty table -// TableNested table = new TableNested(); -// // When we put an item in it -// table.put("foo", 1); -// // And we put a new value with the same key -// table.put("foo", 2); -// // Then we should get back the new value -// Assert.assertEquals(table.get("foo"), new Integer(2)); -// } -// -// @Test -// public void testRemoveAnItem() throws Exception { -// //Given an empty table -// TableNested table = new TableNested(); -// // When we put an item in it -// table.put("foo", 1); -// // And we remove that item -// table.remove("foo"); -// // Then we should get back null for that balue -// Assert.assertEquals(table.get("foo"), null); -// } -//} \ No newline at end of file +package TableNested; + +import org.junit.Assert; +import org.junit.Test; + +public class TableNestedTest { + @Test + public void testGetWithoutAnItemReturnsNull() throws Exception { + // Given an empty table + TableNested table = new TableNested(); + // When we try and get an item then it returns null + Assert.assertEquals(table.get("foo"), null); + } + + @Test + public void testPutAnItemReturnsAndDoesNotDelete() throws Exception { + //Given an empty table + TableNested table = new TableNested(); + // When we put an item in it + table.put("foo", 1); + // Then we should be able to get it's value + Assert.assertEquals(table.get("foo"), new Integer(1)); + // And then we should be able to get it again as it wasn't removed + Assert.assertEquals(table.get("foo"), new Integer(1)); + } + + @Test + public void testOverwritingAnItem() throws Exception { + //Given an empty table + TableNested table = new TableNested(); + // When we put an item in it + table.put("foo", 1); + // And we put a new value with the same key + table.put("foo", 2); + // Then we should get back the new value + Assert.assertEquals(table.get("foo"), new Integer(2)); + } + + @Test + public void testRemoveAnItem() throws Exception { + //Given an empty table + TableNested table = new TableNested(); + // When we put an item in it + table.put("foo", 1); + // And we remove that item + table.remove("foo"); + // Then we should get back null for that balue + Assert.assertEquals(table.get("foo"), null); + } +} \ No newline at end of file From 32b81c00d5120fa6540b6584d0a2e3044160f503 Mon Sep 17 00:00:00 2001 From: Carolynn Vansant Date: Sun, 11 Mar 2018 00:27:49 -0500 Subject: [PATCH 3/7] finished up through part 5 --- src/main/java/Table/Table.java | 21 +++++++++++-------- src/main/java/TableNested/TableNested.java | 18 +++++++++------- src/test/java/Table/TableTest.java | 10 +++++++++ .../java/TableNested/TableNestedTest.java | 11 ++++++++++ 4 files changed, 43 insertions(+), 17 deletions(-) diff --git a/src/main/java/Table/Table.java b/src/main/java/Table/Table.java index d572562..9187022 100644 --- a/src/main/java/Table/Table.java +++ b/src/main/java/Table/Table.java @@ -35,17 +35,20 @@ public int size(){ } public void put(K key, V value) { - entries.add(new Entry<>(key,value)); - //not sure why the for loop won't work but I'll come back to that later -/* for (int i = 0; i < entries.size(); i++) { - K entryKey = entries.get(i).getKey(); - if ((entries.get(i).getKey()).equals(key)) { - entries.set(i, new Entry<>(key,value)); - } else { - entries.add(i, new Entry<>(key,value)); + if(entries.size() == 0){ + entries.add(new Entry<>(key,value)); + } + else{ + for (int i = 0; i < entries.size(); i++) { + K entryKey = entries.get(i).getKey(); + if ((entries.get(i).getKey()).equals(key)) { + entries.set(i, new Entry<>(key, value)); + } else { + entries.add(new Entry<>(key, value)); + } } } -*/ + } public void remove(K key) { diff --git a/src/main/java/TableNested/TableNested.java b/src/main/java/TableNested/TableNested.java index db68967..df0d003 100644 --- a/src/main/java/TableNested/TableNested.java +++ b/src/main/java/TableNested/TableNested.java @@ -35,16 +35,18 @@ public int size(){ } public void put(K key, V value) { - entries.add(new Entry<>(key,value)); - //not sure why the for loop won't work but I'll come back to that later -/* for (int i = 0; i < entries.size(); i++) { - if ((key.equals(entries.get(i).getKey()))){ - entries.set(i, new Entry<>(key,value)); - } else { - entries.add(i, new Entry<>(key,value)); + if(entries.size() == 0) { + entries.add(new Entry<>(key, value)); + } else { + for (int i = 0; i < entries.size(); i++) { + if ((key.equals(entries.get(i).getKey()))) { + entries.set(i, new Entry<>(key, value)); + } else { + entries.add(i, new Entry<>(key, value)); + } } } -*/ + } public void remove(K key) { diff --git a/src/test/java/Table/TableTest.java b/src/test/java/Table/TableTest.java index 5f01248..5d5d529 100644 --- a/src/test/java/Table/TableTest.java +++ b/src/test/java/Table/TableTest.java @@ -25,6 +25,16 @@ public void testPutAnItemReturnsAndDoesNotDelete() throws Exception { Assert.assertEquals(table.get("foo"), new Integer(1)); } + @Test + public void sizeTest(){ + Table table = new Table(); + table.put("foo", 1); + table.put("foo", 2); + int expected = 1; + int actual = table.size(); + Assert.assertEquals(expected, actual); + } + @Test public void testOverwritingAnItem() throws Exception { //Given an empty table diff --git a/src/test/java/TableNested/TableNestedTest.java b/src/test/java/TableNested/TableNestedTest.java index fdf12d5..7eaa656 100644 --- a/src/test/java/TableNested/TableNestedTest.java +++ b/src/test/java/TableNested/TableNestedTest.java @@ -1,5 +1,6 @@ package TableNested; +import Table.Table; import org.junit.Assert; import org.junit.Test; @@ -24,6 +25,16 @@ public void testPutAnItemReturnsAndDoesNotDelete() throws Exception { Assert.assertEquals(table.get("foo"), new Integer(1)); } + @Test + public void sizeTest(){ + TableNested table = new TableNested(); + table.put("foo", 1); + table.put("foo", 2); + int expected = 1; + int actual = table.size(); + Assert.assertEquals(expected, actual); + } + @Test public void testOverwritingAnItem() throws Exception { //Given an empty table From 06e8e58af942c666e3118df41848435a4424dc36 Mon Sep 17 00:00:00 2001 From: Carolynn Vansant Date: Sun, 11 Mar 2018 14:03:35 -0400 Subject: [PATCH 4/7] all parts up through ArrayListCombiner finished, working on MapFunc --- .../ArrayListCombiner/ArrayListCombiner.java | 16 ++++- src/main/java/MapFunc/EntryPair.java | 22 ++++++ src/main/java/MapFunc/MapFunc.java | 66 ++++++++++++++++- .../ArrayListCombinerTest.java | 70 +++++++++---------- src/test/java/MapFunc/MapFuncTest.java | 70 +++++++++---------- src/test/java/Swap/SwapTest.java | 1 + 6 files changed, 172 insertions(+), 73 deletions(-) create mode 100644 src/main/java/MapFunc/EntryPair.java diff --git a/src/main/java/ArrayListCombiner/ArrayListCombiner.java b/src/main/java/ArrayListCombiner/ArrayListCombiner.java index d302cd2..20d93fe 100644 --- a/src/main/java/ArrayListCombiner/ArrayListCombiner.java +++ b/src/main/java/ArrayListCombiner/ArrayListCombiner.java @@ -2,11 +2,23 @@ import java.util.ArrayList; + /** * Create two generic methods that take two arraylists. The methods should both append the second ArrayList's items, * to the first. Use a wildcard for one of the type arguments in each method. * The first method should be called extendCombiner and should use ? extends E * The second method should be called superCombiner and should use ? super E */ -public class ArrayListCombiner { -} +public class ArrayListCombiner { + + Employee.Employee employee; + + public static void extendCombiner(ArrayList firstArray, ArrayList secondArray){ + firstArray.addAll(secondArray); + } + + public static void superCombiner(ArrayList firstArray, ArrayList secondArray){ + firstArray.addAll(secondArray); + } + +} \ No newline at end of file diff --git a/src/main/java/MapFunc/EntryPair.java b/src/main/java/MapFunc/EntryPair.java new file mode 100644 index 0000000..6c7f8bf --- /dev/null +++ b/src/main/java/MapFunc/EntryPair.java @@ -0,0 +1,22 @@ +package MapFunc; + +public class EntryPair { + private K key; + private V value; + + public EntryPair(K key, V value) { + this.key = key; + this.value = value; + } + + public K getKey() { + return key; + } + + public V getValue() { + return value; + } + + + +} diff --git a/src/main/java/MapFunc/MapFunc.java b/src/main/java/MapFunc/MapFunc.java index ed4bf66..244d882 100644 --- a/src/main/java/MapFunc/MapFunc.java +++ b/src/main/java/MapFunc/MapFunc.java @@ -1,5 +1,6 @@ package MapFunc; + import java.util.ArrayList; import java.util.function.Function; @@ -7,6 +8,69 @@ * Create a function called `map` that takes an ArrayList and a `Function` object, * and returns an ArrayList with all of the elements of the first after the function is applied to them. */ -public class MapFunc { +public class MapFunc { + + private EntryPair entry; + private Function function; + + public EntryPair getEntry() { + return entry; + } + + public Function getFunction() { + return function; + } + + public static ArrayList> map(ArrayList array, Function function) { + ArrayList> arrayList = new ArrayList<>(); + for(int i = 0; i(key,value)); +// } +// else{ +// for (int i = 0; i < entries.size(); i++) { +// K entryKey = entries.get(i).getKey(); +// if ((entries.get(i).getKey()).equals(key)) { +// entries.set(i, new Entry<>(key, value)); +// } else { +// entries.add(new Entry<>(key, value)); +// } +// } +// } +// +// } +// +// public void remove(K key) { +// for (int i = 0; i < entries.size(); i++) { +// K entryKey = entries.get(i).getKey(); +// if (entryKey.equals(key)) { +// entries.remove(i); +// } +// } +// } } diff --git a/src/test/java/ArrayListCombiner/ArrayListCombinerTest.java b/src/test/java/ArrayListCombiner/ArrayListCombinerTest.java index 957a878..9e16484 100644 --- a/src/test/java/ArrayListCombiner/ArrayListCombinerTest.java +++ b/src/test/java/ArrayListCombiner/ArrayListCombinerTest.java @@ -9,40 +9,40 @@ import java.util.ArrayList; public class ArrayListCombinerTest { -// Employee foo = new Employee("FOO", 100); -// Manager bar = new Manager("BAR", 100); -// @Test -// public void testExtendCombiner() throws Exception { -// // Given an array list with employees -// ArrayList first = new ArrayList<>(); -// first.add(foo); -// // An an array list with managers -// ArrayList second = new ArrayList<>(); -// second.add(bar); -// // When I combine them -// ArrayListCombiner.extendCombiner(first, second); -// // Then I should get an arrayList with both -// ArrayList expected = new ArrayList<>(); -// expected.add(foo); -// expected.add(bar); -// Assert.assertEquals(expected, first); -// } -// -// @Test -// public void testSuperCombiner() throws Exception { -// // Given an array list with employees -// ArrayList first = new ArrayList<>(); -// first.add(foo); -// // An an array list with managers -// ArrayList second = new ArrayList<>(); -// second.add(bar); -// // When I combine them -// ArrayListCombiner.superCombiner(first, second); -// // Then I should get an arrayList with both -// ArrayList expected = new ArrayList<>(); -// expected.add(foo); -// expected.add(bar); -// Assert.assertEquals(expected, first); -// } + Employee foo = new Employee("FOO", 100); + Manager bar = new Manager("BAR", 100); + @Test + public void testExtendCombiner() throws Exception { + // Given an array list with employees + ArrayList first = new ArrayList<>(); + first.add(foo); + // An an array list with managers + ArrayList second = new ArrayList<>(); + second.add(bar); + // When I combine them + ArrayListCombiner.extendCombiner(first, second); + // Then I should get an arrayList with both + ArrayList expected = new ArrayList<>(); + expected.add(foo); + expected.add(bar); + Assert.assertEquals(expected, first); + } + + @Test + public void testSuperCombiner() throws Exception { + // Given an array list with employees + ArrayList first = new ArrayList<>(); + first.add(foo); + // An an array list with managers + ArrayList second = new ArrayList<>(); + second.add(bar); + // When I combine them + ArrayListCombiner.superCombiner(first, second); + // Then I should get an arrayList with both + ArrayList expected = new ArrayList<>(); + expected.add(foo); + expected.add(bar); + Assert.assertEquals(expected, first); + } } \ No newline at end of file diff --git a/src/test/java/MapFunc/MapFuncTest.java b/src/test/java/MapFunc/MapFuncTest.java index 3c7534f..f6459a7 100644 --- a/src/test/java/MapFunc/MapFuncTest.java +++ b/src/test/java/MapFunc/MapFuncTest.java @@ -1,36 +1,36 @@ -//package MapFunc; -// -//import MapFunc.MapFunc; -//import org.junit.Test; -// -//import java.util.ArrayList; -//import org.junit.Assert; -// -//public class MapFuncTest { -// @Test -// public void testSingleTypeMap() throws Exception { -// // Given an integer array list -// ArrayList intList = new ArrayList<>(); -// intList.add(1); -// intList.add(2); -// // When it's mapped with a function to double the value -// ArrayList mappedList = MapFunc.map(intList, num -> num*2); -// // Then all the values are doubled -// Assert.assertEquals(new Integer(2), mappedList.get(0)); -// Assert.assertEquals(new Integer(4), mappedList.get(1)); -// } -// -// @Test -// public void testMultipleTypeMap() throws Exception { -// // Given an integer array list -// ArrayList intList = new ArrayList<>(); -// intList.add(1); -// intList.add(2); -// // When it's mapped with to string -// ArrayList mappedList = MapFunc.map(intList, num -> num.toString()); -// // Then all the values are doubled -// Assert.assertEquals("1", mappedList.get(0)); -// Assert.assertEquals("2", mappedList.get(1)); -// } -// +package MapFunc; + +import MapFunc.MapFunc; +import org.junit.Test; + +import java.util.ArrayList; +import org.junit.Assert; + +public class MapFuncTest { + @Test + public void testSingleTypeMap() throws Exception { + // Given an integer array list + ArrayList intList = new ArrayList<>(); + intList.add(1); + intList.add(2); + // When it's mapped with a function to double the value + ArrayList mappedList = MapFunc.map(intList, num -> num*2); + // Then all the values are doubled + Assert.assertEquals(new Integer(2), mappedList.get(0)); + Assert.assertEquals(new Integer(4), mappedList.get(1)); + } + + @Test + public void testMultipleTypeMap() throws Exception { + // Given an integer array list + ArrayList intList = new ArrayList<>(); + intList.add(1); + intList.add(2); + // When it's mapped with to string + ArrayList mappedList = MapFunc.map(intList, num -> num.toString()); + // Then all the values are turned into Strings + Assert.assertEquals("1", mappedList.get(0)); + Assert.assertEquals("2", mappedList.get(1)); + } + //} \ No newline at end of file diff --git a/src/test/java/Swap/SwapTest.java b/src/test/java/Swap/SwapTest.java index 4ee6f4b..6fd3729 100644 --- a/src/test/java/Swap/SwapTest.java +++ b/src/test/java/Swap/SwapTest.java @@ -3,6 +3,7 @@ import org.junit.Assert; import org.junit.Test; + /** * Get the tests passing. */ From 54a5c972b77f1ea39a4e21de8e161234a5f73d87 Mon Sep 17 00:00:00 2001 From: Carolynn Vansant Date: Sun, 11 Mar 2018 17:54:00 -0400 Subject: [PATCH 5/7] part 7 finished --- src/main/java/MapFunc/MapFunc.java | 65 +++----------------------- src/test/java/MapFunc/MapFuncTest.java | 2 +- 2 files changed, 7 insertions(+), 60 deletions(-) diff --git a/src/main/java/MapFunc/MapFunc.java b/src/main/java/MapFunc/MapFunc.java index 244d882..5e8583c 100644 --- a/src/main/java/MapFunc/MapFunc.java +++ b/src/main/java/MapFunc/MapFunc.java @@ -10,67 +10,14 @@ */ public class MapFunc { - private EntryPair entry; - private Function function; - public EntryPair getEntry() { - return entry; - } - - public Function getFunction() { - return function; - } - - public static ArrayList> map(ArrayList array, Function function) { - ArrayList> arrayList = new ArrayList<>(); - for(int i = 0; i ArrayList map(ArrayList array, Function function) { + ArrayList entryPairs = new ArrayList<>(); + for(T item: array){ + R result = function.apply(item); + entryPairs.add(result); } - return arrayList; + return entryPairs; } - -// -// public R get(T key) { -// R value = null; -// for (int i = 0; i < arrayList.size(); i++) { -// T entryKey = (T) arrayList.get(i).getKey(); -// if (entryKey.equals(key)) { -// value = (R)arrayList.get(i).getValue(); -// } -// } -// return value; -// } -// public int size(){ -// return entries.size(); -// } -// -// public void put(K key, V value) { -// if(entries.size() == 0){ -// entries.add(new Entry<>(key,value)); -// } -// else{ -// for (int i = 0; i < entries.size(); i++) { -// K entryKey = entries.get(i).getKey(); -// if ((entries.get(i).getKey()).equals(key)) { -// entries.set(i, new Entry<>(key, value)); -// } else { -// entries.add(new Entry<>(key, value)); -// } -// } -// } -// -// } -// -// public void remove(K key) { -// for (int i = 0; i < entries.size(); i++) { -// K entryKey = entries.get(i).getKey(); -// if (entryKey.equals(key)) { -// entries.remove(i); -// } -// } -// } } diff --git a/src/test/java/MapFunc/MapFuncTest.java b/src/test/java/MapFunc/MapFuncTest.java index f6459a7..2177ae5 100644 --- a/src/test/java/MapFunc/MapFuncTest.java +++ b/src/test/java/MapFunc/MapFuncTest.java @@ -33,4 +33,4 @@ public void testMultipleTypeMap() throws Exception { Assert.assertEquals("2", mappedList.get(1)); } -//} \ No newline at end of file +} \ No newline at end of file From a8b2ed343665d4e7967627bd3dd6c2b7fe214cd2 Mon Sep 17 00:00:00 2001 From: Carolynn Vansant Date: Sun, 11 Mar 2018 19:30:40 -0400 Subject: [PATCH 6/7] all 8 parts completed, putting in pull request --- src/main/java/MapFunc/EntryPair.java | 22 ---- src/main/java/Pair/Arrays.java | 37 ++++++- src/main/java/Pair/Pair.java | 39 ++++++- src/test/java/Pair/ArraysTest.java | 148 +++++++++++++-------------- src/test/java/Pair/PairTest.java | 64 ++++++------ 5 files changed, 178 insertions(+), 132 deletions(-) delete mode 100644 src/main/java/MapFunc/EntryPair.java diff --git a/src/main/java/MapFunc/EntryPair.java b/src/main/java/MapFunc/EntryPair.java deleted file mode 100644 index 6c7f8bf..0000000 --- a/src/main/java/MapFunc/EntryPair.java +++ /dev/null @@ -1,22 +0,0 @@ -package MapFunc; - -public class EntryPair { - private K key; - private V value; - - public EntryPair(K key, V value) { - this.key = key; - this.value = value; - } - - public K getKey() { - return key; - } - - public V getValue() { - return value; - } - - - -} diff --git a/src/main/java/Pair/Arrays.java b/src/main/java/Pair/Arrays.java index 07bf207..d34aed3 100644 --- a/src/main/java/Pair/Arrays.java +++ b/src/main/java/Pair/Arrays.java @@ -10,7 +10,38 @@ * A max method that returns the largest item in the arraylist * And a minmax method that returns a pair containing the largest and smallest items from the array list */ -/*public class Arrays { - public static <___> Pair firstLast(ArrayList<___> a) { + +public class Arrays { + + public static > Pair firstLast(ArrayList a){ + return new Pair(a.get(0), a.get(a.size()-1)); + } + + public static > E min(ArrayList a) { + E min = a.get(0); + for (int i = 0; i < a.size(); i++) { + if (min.compareTo(a.get(i)) > 0) min = a.get(i); + } + return min; + } + + public static > E max(ArrayList a) { + E max = a.get(0); + for (int i = 0; i < a.size(); i++) { + if (max.compareTo(a.get(i)) < 0) max = a.get(i); + } + return max; + } + + public static > Pair minMax(ArrayList a) { + E min = a.get(0); + E max = a.get(0); + for(int i = 0; i0) min = a.get(i); + if(max.compareTo(a.get(i))<0) max = a.get(i); + } + return new Pair<>(min,max); } -}*/ + + +} diff --git a/src/main/java/Pair/Pair.java b/src/main/java/Pair/Pair.java index c4dd905..a99788c 100644 --- a/src/main/java/Pair/Pair.java +++ b/src/main/java/Pair/Pair.java @@ -1,5 +1,9 @@ package Pair; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Comparator; + /** * You need to store two values of type `E`, set them in a constructor, and have the following methods, * getFirst @@ -7,6 +11,39 @@ * min -> returns the minimum of the pair * max -> returns the maximum of the pair */ -public class Pair { + +public class Pair> implements Comparable> { + + private E first; + private E second; + + public Pair(E first, E second){ + this.first = first; + this.second = second; + } + + public E getFirst() { + return first; + } + + public E getSecond() { + return second; + } + + public E min(){ + if(first.compareTo(second)>0) return second; + else return first; + } + + public E max(){ + if(first.compareTo(second)>0) return first; + else return second; + } + + @Override + public int compareTo(Pair o) { + return 0; + } + } diff --git a/src/test/java/Pair/ArraysTest.java b/src/test/java/Pair/ArraysTest.java index 4d32e23..0d51970 100644 --- a/src/test/java/Pair/ArraysTest.java +++ b/src/test/java/Pair/ArraysTest.java @@ -1,74 +1,74 @@ -//package Pair; -// -//import org.junit.Assert; -//import org.junit.Test; -// -//import java.util.ArrayList; -// -//public class ArraysTest { -// @Test -// public void firstLast() throws Exception { -// // Given an ArrayList of Integers -// ArrayList al = new ArrayList<>(); -// al.add(1); -// al.add(5); -// al.add(3); -// al.add(4); -// al.add(2); -// al.add(0); -// al.add(1000); -// // When firstLast is called -// Pair result = Arrays.firstLast(al); -// // Then it should return the first and last items -// Assert.assertEquals(new Integer(1), result.getFirst()); -// Assert.assertEquals(new Integer(1000), result.getSecond()); -// } -// -// @Test -// public void testMin() throws Exception { -// // Given an ArrayList of Integers -// ArrayList al = new ArrayList<>(); -// al.add(1); -// al.add(5); -// al.add(3); -// al.add(4); -// al.add(2); -// al.add(0); -// al.add(1000); -// // When min is called assert that it gets the smallest item -// Assert.assertEquals(new Integer(0), Arrays.min(al)); -// } -// -// @Test -// public void testMax() throws Exception { -// // Given an ArrayList of Integers -// ArrayList al = new ArrayList<>(); -// al.add(1); -// al.add(5); -// al.add(3); -// al.add(4); -// al.add(2); -// al.add(0); -// al.add(1000); -// // When min is called assert that it gets the largest item -// Assert.assertEquals(new Integer(1000), Arrays.max(al)); -// } -// -// @Test -// public void testMinMax() throws Exception { -// // Given an ArrayList of Integers -// ArrayList al = new ArrayList<>(); -// al.add(1); -// al.add(5); -// al.add(3); -// al.add(4); -// al.add(2); -// al.add(0); -// al.add(1000); -// // When minMax is called -// Pair result = Arrays.minMax(al); -// // Then it should return the first and last items -// Assert.assertEquals(new Integer(0), result.min()); -// Assert.assertEquals(new Integer(1000), result.max()); -// } -//} +package Pair; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +public class ArraysTest { + @Test + public void firstLast() throws Exception { + // Given an ArrayList of Integers + ArrayList al = new ArrayList<>(); + al.add(1); + al.add(5); + al.add(3); + al.add(4); + al.add(2); + al.add(0); + al.add(1000); + // When firstLast is called + Pair result = Arrays.firstLast(al); + // Then it should return the first and last items + Assert.assertEquals(new Integer(1), result.getFirst()); + Assert.assertEquals(new Integer(1000), result.getSecond()); + } + + @Test + public void testMin() throws Exception { + // Given an ArrayList of Integers + ArrayList al = new ArrayList<>(); + al.add(1); + al.add(5); + al.add(3); + al.add(4); + al.add(2); + al.add(0); + al.add(1000); + // When min is called assert that it gets the smallest item + Assert.assertEquals(new Integer(0), Arrays.min(al)); + } + + @Test + public void testMax() throws Exception { + // Given an ArrayList of Integers + ArrayList al = new ArrayList<>(); + al.add(1); + al.add(5); + al.add(3); + al.add(4); + al.add(2); + al.add(0); + al.add(1000); + // When min is called assert that it gets the largest item + Assert.assertEquals(new Integer(1000), Arrays.max(al)); + } + + @Test + public void testMinMax() throws Exception { + // Given an ArrayList of Integers + ArrayList al = new ArrayList<>(); + al.add(1); + al.add(5); + al.add(3); + al.add(4); + al.add(2); + al.add(0); + al.add(1000); + // When minMax is called + Pair result = Arrays.minMax(al); + // Then it should return the first and last items + Assert.assertEquals(new Integer(0), result.min()); + Assert.assertEquals(new Integer(1000), result.max()); + } +} diff --git a/src/test/java/Pair/PairTest.java b/src/test/java/Pair/PairTest.java index d616178..baf2071 100644 --- a/src/test/java/Pair/PairTest.java +++ b/src/test/java/Pair/PairTest.java @@ -1,32 +1,32 @@ -//package Pair; -// -//import org.junit.Test; -//import org.junit.Assert; -// -//public class PairTest { -// -// @Test -// public void testGetters() throws Exception { -// // Given a pair with "Foo" and "Bar" -// Pair p = new Pair("Foo", "Bar"); -// // When getFirst and getSecond are called, they should be returned. -// Assert.assertEquals("Foo", p.getFirst()); -// Assert.assertEquals("Bar", p.getSecond()); -// } -// -// @Test -// public void testMin() throws Exception { -// // Given a pair with two values -// Pair p = new Pair(1.23, 2.34); -// // When p.min() is called, the smallest should be returned. -// Assert.assertEquals(new Double(1.23), p.min()); -// } -// -// @Test -// public void testMax() throws Exception { -// // Given a pair with two values -// Pair p = new Pair(1.23, 2.34); -// // When p.max() is called, the largest should be returned. -// Assert.assertEquals(new Double(2.34), p.max()); -// } -//} \ No newline at end of file +package Pair; + +import org.junit.Test; +import org.junit.Assert; + +public class PairTest { + + @Test + public void testGetters() throws Exception { + // Given a pair with "Foo" and "Bar" + Pair p = new Pair("Foo", "Bar"); + // When getFirst and getSecond are called, they should be returned. + Assert.assertEquals("Foo", p.getFirst()); + Assert.assertEquals("Bar", p.getSecond()); + } + + @Test + public void testMin() throws Exception { + // Given a pair with two values + Pair p = new Pair(1.23, 2.34); + // When p.min() is called, the smallest should be returned. + Assert.assertEquals(new Double(1.23), p.min()); + } + + @Test + public void testMax() throws Exception { + // Given a pair with two values + Pair p = new Pair(1.23, 2.34); + // When p.max() is called, the largest should be returned. + Assert.assertEquals(new Double(2.34), p.max()); + } +} \ No newline at end of file From be87d469c3f8a53a334684dda50f01b0d6486ff8 Mon Sep 17 00:00:00 2001 From: Carolynn Vansant Date: Thu, 17 Jun 2021 09:34:09 -0400 Subject: [PATCH 7/7] minor updates --- .../ArrayListCombiner/ArrayListCombiner.java | 2 +- src/main/java/Employee/Employee.java | 1 + src/main/java/Employee/Manager.java | 1 + src/main/java/Pair/Arrays.java | 2 +- src/main/java/Pair/Pair.java | 5 +++ src/main/java/StackArrayList/Stack.java | 2 ++ src/main/java/Swap/Swap.java | 1 + src/main/java/Table/Table.java | 7 ++-- src/test/java/Pair/ArraysTest.java | 36 +++---------------- src/test/java/Table/TableTest.java | 2 +- 10 files changed, 21 insertions(+), 38 deletions(-) diff --git a/src/main/java/ArrayListCombiner/ArrayListCombiner.java b/src/main/java/ArrayListCombiner/ArrayListCombiner.java index 20d93fe..cff3348 100644 --- a/src/main/java/ArrayListCombiner/ArrayListCombiner.java +++ b/src/main/java/ArrayListCombiner/ArrayListCombiner.java @@ -3,6 +3,7 @@ import java.util.ArrayList; + /** * Create two generic methods that take two arraylists. The methods should both append the second ArrayList's items, * to the first. Use a wildcard for one of the type arguments in each method. @@ -11,7 +12,6 @@ */ public class ArrayListCombiner { - Employee.Employee employee; public static void extendCombiner(ArrayList firstArray, ArrayList secondArray){ firstArray.addAll(secondArray); diff --git a/src/main/java/Employee/Employee.java b/src/main/java/Employee/Employee.java index 8355e6e..ef851ef 100644 --- a/src/main/java/Employee/Employee.java +++ b/src/main/java/Employee/Employee.java @@ -1,6 +1,7 @@ package Employee; public class Employee { + private String name; private double salary; diff --git a/src/main/java/Employee/Manager.java b/src/main/java/Employee/Manager.java index 7103896..7df8da5 100644 --- a/src/main/java/Employee/Manager.java +++ b/src/main/java/Employee/Manager.java @@ -12,6 +12,7 @@ public void setBonus(double bonus) { this.bonus = bonus; } + @Override public double getSalary() { // Overrides superclass method return super.getSalary() + bonus; } diff --git a/src/main/java/Pair/Arrays.java b/src/main/java/Pair/Arrays.java index d34aed3..1fe8937 100644 --- a/src/main/java/Pair/Arrays.java +++ b/src/main/java/Pair/Arrays.java @@ -11,7 +11,7 @@ * And a minmax method that returns a pair containing the largest and smallest items from the array list */ -public class Arrays { +public class Arrays> { public static > Pair firstLast(ArrayList a){ return new Pair(a.get(0), a.get(a.size()-1)); diff --git a/src/main/java/Pair/Pair.java b/src/main/java/Pair/Pair.java index a99788c..ad60e70 100644 --- a/src/main/java/Pair/Pair.java +++ b/src/main/java/Pair/Pair.java @@ -42,6 +42,11 @@ public E max(){ @Override public int compareTo(Pair o) { +// if(first.equals(o.getFirst())){ +// return 0; +// } else if (){ +// return 1; +// } return 0; } diff --git a/src/main/java/StackArrayList/Stack.java b/src/main/java/StackArrayList/Stack.java index 9bdff0d..8557e43 100644 --- a/src/main/java/StackArrayList/Stack.java +++ b/src/main/java/StackArrayList/Stack.java @@ -7,6 +7,8 @@ * If you pop on an empty stack, throw an IndexOutOfBoundsException. */ public class Stack { + + private ArrayList elements; diff --git a/src/main/java/Swap/Swap.java b/src/main/java/Swap/Swap.java index 19984a5..d9fe337 100644 --- a/src/main/java/Swap/Swap.java +++ b/src/main/java/Swap/Swap.java @@ -4,6 +4,7 @@ * Keep this. Just make it so the tests pass. */ public class Swap { + public static T[] swap(int i, int j, T... values) { T temp = values[i]; values[i] = values[j]; diff --git a/src/main/java/Table/Table.java b/src/main/java/Table/Table.java index 9187022..f0e761d 100644 --- a/src/main/java/Table/Table.java +++ b/src/main/java/Table/Table.java @@ -10,6 +10,7 @@ * Void return on `remove`. */ public class Table { + private ArrayList> entries; public Table() { @@ -37,10 +38,8 @@ public int size(){ public void put(K key, V value) { if(entries.size() == 0){ entries.add(new Entry<>(key,value)); - } - else{ + } else{ for (int i = 0; i < entries.size(); i++) { - K entryKey = entries.get(i).getKey(); if ((entries.get(i).getKey()).equals(key)) { entries.set(i, new Entry<>(key, value)); } else { @@ -60,4 +59,6 @@ public void remove(K key) { } } + + } diff --git a/src/test/java/Pair/ArraysTest.java b/src/test/java/Pair/ArraysTest.java index 0d51970..27fc11e 100644 --- a/src/test/java/Pair/ArraysTest.java +++ b/src/test/java/Pair/ArraysTest.java @@ -9,14 +9,7 @@ public class ArraysTest { @Test public void firstLast() throws Exception { // Given an ArrayList of Integers - ArrayList al = new ArrayList<>(); - al.add(1); - al.add(5); - al.add(3); - al.add(4); - al.add(2); - al.add(0); - al.add(1000); + ArrayList al = new ArrayList<>(java.util.Arrays.asList(1,5,3,4,2,0,1000)); // When firstLast is called Pair result = Arrays.firstLast(al); // Then it should return the first and last items @@ -27,14 +20,7 @@ public void firstLast() throws Exception { @Test public void testMin() throws Exception { // Given an ArrayList of Integers - ArrayList al = new ArrayList<>(); - al.add(1); - al.add(5); - al.add(3); - al.add(4); - al.add(2); - al.add(0); - al.add(1000); + ArrayList al = new ArrayList<>(java.util.Arrays.asList(1,5,3,4,2,0,1000)); // When min is called assert that it gets the smallest item Assert.assertEquals(new Integer(0), Arrays.min(al)); } @@ -42,14 +28,7 @@ public void testMin() throws Exception { @Test public void testMax() throws Exception { // Given an ArrayList of Integers - ArrayList al = new ArrayList<>(); - al.add(1); - al.add(5); - al.add(3); - al.add(4); - al.add(2); - al.add(0); - al.add(1000); + ArrayList al = new ArrayList<>(java.util.Arrays.asList(1,5,3,4,2,0,1000)); // When min is called assert that it gets the largest item Assert.assertEquals(new Integer(1000), Arrays.max(al)); } @@ -57,14 +36,7 @@ public void testMax() throws Exception { @Test public void testMinMax() throws Exception { // Given an ArrayList of Integers - ArrayList al = new ArrayList<>(); - al.add(1); - al.add(5); - al.add(3); - al.add(4); - al.add(2); - al.add(0); - al.add(1000); + ArrayList al = new ArrayList<>(java.util.Arrays.asList(1,5,3,4,2,0,1000)); // When minMax is called Pair result = Arrays.minMax(al); // Then it should return the first and last items diff --git a/src/test/java/Table/TableTest.java b/src/test/java/Table/TableTest.java index 5d5d529..f9bfb48 100644 --- a/src/test/java/Table/TableTest.java +++ b/src/test/java/Table/TableTest.java @@ -55,7 +55,7 @@ public void testRemoveAnItem() throws Exception { table.put("foo", 1); // And we remove that item table.remove("foo"); - // Then we should get back null for that balue + // Then we should get back null for that value Assert.assertEquals(table.get("foo"), null); } } \ No newline at end of file