forked from GreenRiverCollege-SDEV301/LetterInventory
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5c197dc
Showing
8 changed files
with
368 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### IntelliJ IDEA ### | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/tests" isTestSource="true" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="module-library" scope="TEST"> | ||
<library name="JUnit5.8.1"> | ||
<CLASSES> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" /> | ||
</CLASSES> | ||
<JAVADOC /> | ||
<SOURCES /> | ||
</library> | ||
</orderEntry> | ||
</component> | ||
</module> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package driver; | ||
|
||
import inventory.LetterInventory; | ||
|
||
public class Driver { | ||
|
||
public static void main(String[] args) { | ||
LetterInventory inv = new LetterInventory(); | ||
//LetterInventory inv = new LetterInventory("WashingtonState"); | ||
System.out.println(inv); | ||
|
||
System.out.println(inv.get('e')); | ||
System.out.println(inv.getIndex('e')); | ||
|
||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,148 @@ | ||
package inventory; | ||
|
||
/** | ||
* This class represents an inventory of the 26 letters in the English alphabet. | ||
* A LetterInventory object keeps track of how many a’s, how many b’s, etc. | ||
* are contained in the inventory. This object stores the counts of the letters | ||
* in an integer array with a maximum count of Short.MAX_VALUE for each letter | ||
* For example: | ||
* the letter inventory for the string “WashingtonState” corresponds to | ||
* [aaeghinnosstttw] --> String representation of the inventory | ||
* [2,0,0,0,1,0,1,1,1,0,0,0,0,2,1,0,0,0,2,3,0,0,1,0,0,0] --> inventory count array | ||
* [a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z] --> corresponding letters | ||
* The case of the letter is ignored, so ‘s’ and ‘S’ are exactly the same. | ||
* | ||
*/ | ||
public class LetterInventory { | ||
|
||
private short[] inventory; // inventory is null here | ||
public static final byte ALPHABET_SIZE = 26; | ||
|
||
/** | ||
* Constructs an integer array for the size of the alphabet. | ||
* All letter counts are initialized to zero. | ||
*/ | ||
public LetterInventory(){ | ||
inventory = new short[ALPHABET_SIZE]; | ||
} | ||
/** | ||
* Constructs an integer array for the size of the alphabet. | ||
* Each element in the array should hold a 16-bit integer | ||
* and adds each character in the text to the inventory | ||
* @param text | ||
*/ | ||
public LetterInventory(String text) { | ||
//TODO | ||
} | ||
|
||
/** | ||
* Identifies the index for the given character within the inventory array , throws an | ||
* IIegalArgumentException if the character is not in the a-z or A-Z range. | ||
* For example: if the given character is 'c' or 'C', then the index returned is 2 | ||
* if the given character is '?', then an IllegalArgumentException is thrown | ||
* | ||
* @param c a-z or A-Z character | ||
* @return index of the character | ||
*/ | ||
public int getIndex(char c) { | ||
//TODO | ||
return 0; | ||
} | ||
|
||
/** | ||
* Increases the count for the given character in the inventory | ||
* @param c a-z or A-Z otherwise an IllegalArgumentException is thrown | ||
*/ | ||
public void add(char c) { | ||
//TODO | ||
} | ||
|
||
/** | ||
* Decreases the count for the given character in the inventory | ||
* @param c a-z or A-Z otherwise an IllegalArgumentException is thrown | ||
*/ | ||
public void subtract(char c) { | ||
//TODO | ||
} | ||
|
||
/** | ||
* Returns the count for the given character in the inventory | ||
* @param c a-z or A-Z otherwise an IllegalArgumentException is thrown | ||
*/ | ||
public int get(char c) { | ||
//TODO | ||
return 0; | ||
} | ||
|
||
/** | ||
* Sets the count for the given character in the inventory | ||
* @param c a-z or A-Z otherwise an IllegalArgumentException is thrown | ||
* @param count the number of occurrences of the character c; if count < 0 | ||
* IllegalArgumentException is thrown | ||
*/ | ||
public void set(char c, short count) { | ||
//TODO | ||
} | ||
|
||
/** | ||
* Determines if a character's count is in the inventory | ||
* @param c a-z or A-Z otherwise an IllegalArgumentException is thrown | ||
* @return true if character is in inventory, false otherwise | ||
*/ | ||
public boolean contains(char c) { | ||
//TODO | ||
return false; | ||
} | ||
|
||
/** | ||
* Return the total count of all letters in the inventory | ||
* @return total count | ||
*/ | ||
public int size() { | ||
//TODO | ||
return 0; | ||
} | ||
|
||
/** | ||
* Determine if the inventory has zero counts for all letters | ||
* @return true, if empty, false otherwise | ||
*/ | ||
public boolean isEmpty() { | ||
// TODO | ||
return false; | ||
} | ||
|
||
/** | ||
* Returns a String representation of the inventory with the letters all in | ||
* lowercase | ||
* surrounded by square brackets in alphabetical order. The number of | ||
* occurrences of | ||
* each letter matches its count in the inventory. | ||
* For example, an inventory of 4 a’s, 1 b, 1 k and 1 m would be represented as | ||
* “[aaaabkm]”. | ||
* | ||
* @return a bracketed string representation of the letters contained in the | ||
* inventory | ||
*/ | ||
public String toString() { | ||
// If you are concatenating many strings together, StringBuilder class | ||
// is often more efficient | ||
StringBuilder toReturn = new StringBuilder("["); | ||
|
||
// for every count in the letters inventory | ||
for (int i = 0; i < inventory.length; i++) { | ||
// add each character to the string count times | ||
for (int count = 0; count < inventory[i]; count++) { | ||
// ascii math performed here | ||
// Example: | ||
// 'a' + 0 = 'a' | ||
// 'a' + 1 = 'b' | ||
// 'a' + 2 = 'c' | ||
// 'a' + 25 = 'z' | ||
toReturn.append((char) ('a' + i)); | ||
} | ||
} | ||
return toReturn.append("]").toString(); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,129 @@ | ||
package inventory; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class LetterInventoryTest { | ||
/* | ||
static LetterInventory washington; | ||
static LetterInventory empty; | ||
static LetterInventory atoz; | ||
@BeforeEach | ||
void setUp() { | ||
washington = new LetterInventory("WashingtonState"); | ||
empty = new LetterInventory(); | ||
atoz = new LetterInventory("abcdefghijklmnopqrstuvwxyz"); | ||
} | ||
@Test | ||
void getIndex() { | ||
for (int i = 0; i < LetterInventory.ALPHABET_SIZE; i++) { | ||
assertEquals(i,washington.getIndex((char)('a' + i))); | ||
} | ||
} | ||
@Test | ||
void add() { | ||
assertEquals("[abcdefghijklmnopqrstuvwxyz]",atoz.toString()); | ||
} | ||
@Test | ||
public void testAddException() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
// Add your code that is expected to throw the exception | ||
atoz.add('?'); | ||
} | ||
); | ||
} | ||
@Test | ||
void subtract() { | ||
washington.subtract('a'); | ||
assertEquals("[aeghinnosstttw]", washington.toString()); | ||
} | ||
@Test | ||
public void testSubtractException() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
// Add your code that is expected to throw the exception | ||
atoz.subtract('?'); | ||
} | ||
); | ||
} | ||
@Test | ||
void get() { | ||
assertEquals(3, washington.get('t')); | ||
} | ||
@Test | ||
public void testGetException() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
// Add your code that is expected to throw the exception | ||
atoz.get('?'); | ||
} | ||
); | ||
} | ||
@Test | ||
void set() { | ||
washington.set('z', (short) 5); | ||
assertEquals("[aaeghinnosstttwzzzzz]", washington.toString()); | ||
} | ||
@Test | ||
public void testSetException() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
// Add your code that is expected to throw the exception | ||
atoz.set('?',(short) 2); | ||
} | ||
); | ||
} | ||
@Test | ||
public void testSetException2() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
// Add your code that is expected to throw the exception | ||
atoz.set('a',(short) -2); | ||
} | ||
); | ||
} | ||
@Test | ||
void contains() { | ||
assertTrue(washington.contains('a')); | ||
assertFalse(washington.contains('x')); | ||
} | ||
@Test | ||
public void testContainsException() { | ||
assertThrows(IllegalArgumentException.class, () -> { | ||
// Add your code that is expected to throw the exception | ||
atoz.contains('?'); | ||
} | ||
); | ||
} | ||
@Test | ||
void size() { | ||
assertEquals(0,empty.size()); | ||
assertEquals(26,atoz.size()); | ||
assertEquals(15,washington.size()); | ||
} | ||
@Test | ||
void isEmpty() { | ||
assertTrue(empty.isEmpty()); | ||
assertFalse(atoz.isEmpty()); | ||
assertFalse(washington.isEmpty()); | ||
} | ||
*/ | ||
} |