Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tevin #1

Open
wants to merge 33 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
599c406
tevin was here
TevinGlover Dec 11, 2023
9571bde
Merge pull request #1 from BiscottiZCW/tevin
TevinGlover Dec 11, 2023
b5b7891
Added test directory, made classes. Now onto making tests
louiecasula Dec 11, 2023
e7c6391
Merge pull request #2 from louiecasula/dev
louiecasula Dec 11, 2023
2418e98
Added test directory and class for GroceryList
louiecasula Dec 11, 2023
4e41215
Merge pull request #3 from louiecasula/dev
louiecasula Dec 11, 2023
074cb81
created createFormatStringTest
louiecasula Dec 11, 2023
ef71262
Merge pull request #4 from louiecasula/dev
louiecasula Dec 11, 2023
607db4e
Grocery List Stuff
NathanG741 Dec 11, 2023
db0f768
Merge remote-tracking branch 'origin/dev' into dev
NathanG741 Dec 11, 2023
5db14af
holes in my plans
TevinGlover Dec 11, 2023
e54da0d
Merge pull request #5 from TevinGlover/tevin
TevinGlover Dec 11, 2023
002a53f
Added Error
NathanG741 Dec 11, 2023
f9ca9bc
Fixed Error
NathanG741 Dec 11, 2023
ff210bf
fixed the JerksonIOTest
louiecasula Dec 11, 2023
fdbacf4
Merge pull request #6 from louiecasula/dev
louiecasula Dec 11, 2023
39b7021
working on regex methods inside GroceryItem
louiecasula Dec 11, 2023
e01647b
Merge pull request #7 from louiecasula/dev
louiecasula Dec 11, 2023
f4694e4
put the original constructor for GroceryItem back in
louiecasula Dec 11, 2023
9146e44
Merge pull request #8 from louiecasula/dev
louiecasula Dec 11, 2023
3d9fa70
Fixed Error
NathanG741 Dec 11, 2023
6a6dfb7
Merge remote-tracking branch 'origin/dev' into dev
NathanG741 Dec 11, 2023
0894c39
added a first edition of the extraction methods
louiecasula Dec 11, 2023
8a3b84a
Merge pull request #9 from louiecasula/dev
louiecasula Dec 11, 2023
a7c2ff4
Finished Tests
NathanG741 Dec 11, 2023
9757fa4
Merge remote-tracking branch 'origin/dev' into dev
NathanG741 Dec 11, 2023
aea967e
updated the extract methods
louiecasula Dec 11, 2023
1f04591
Merge pull request #10 from louiecasula/dev
louiecasula Dec 11, 2023
7eefac3
Merge pull request #11 from TevinGlover/tevin
TevinGlover Dec 11, 2023
d732dd4
Merge pull request #12 from BiscottiZCW/tevin
TevinGlover Dec 11, 2023
b7410bf
Merge pull request #13 from TevinGlover/tevin
TevinGlover Dec 11, 2023
0750d3a
i ripped my pants
TevinGlover Dec 11, 2023
b97add1
Merge pull request #14 from TevinGlover/tevin
TevinGlover Dec 11, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
89 changes: 89 additions & 0 deletions src/main/java/GroceryItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class GroceryItem {
String name;
String price;
String type;
String expiration;
Pattern pattern;
Matcher matcher;

public GroceryItem(String segment) {
this.name = extractName(segment);
this.price = extractPrice(segment);
this.type = extractType(segment);
this.expiration = extractExpiration(segment);
}

public GroceryItem(String name, String price, String type, String expiration) {
this.name = name;
this.price = price;
this.type = type;
this.expiration = expiration;
}

public void setName(String name) {
this.name = name;
}

public String getName() {
return name;
}

public String getPrice() {
return price;
}

public String getType() {
return type;
}

public String getExpiration() {
return expiration;
}

public String extractName(String segment){
pattern = Pattern.compile("[nN]..[eE]:(\\w*);", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(segment);
if (matcher.find()){
return matcher.group(0);
}
else {
return "";
}
}

public String extractPrice(String segment){
pattern = Pattern.compile("[pP]...[eE]:(\\d\\.\\d\\d);", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(segment);
if (matcher.find()){
return matcher.group(0);
}
else {
return "";
}
}

public String extractType(String segment){
pattern = Pattern.compile("[tT]..[eE]:(\\w*);", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(segment);
if (matcher.find()){
return matcher.group(0);
}
else {
return "";
}
}

public String extractExpiration(String segment){
pattern = Pattern.compile("[eE]........[nN]:(.*)##", Pattern.CASE_INSENSITIVE);
matcher = pattern.matcher(segment);
if (matcher.find()){
return matcher.group(0);
}
else {
return "";
}
}
}
34 changes: 34 additions & 0 deletions src/main/java/GroceryList.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@

import java.util.ArrayList;

public class GroceryList extends ArrayList<ArrayList<GroceryItem>> {

ArrayList<GroceryItem> Milk;
ArrayList<GroceryItem> Bread;
ArrayList<GroceryItem> Cookies;
ArrayList<GroceryItem> Apples;
int Error;

public GroceryList() {
this.Milk = new ArrayList<>();
this.Bread = new ArrayList<>();
this.Cookies = new ArrayList<>();
this.Apples = new ArrayList<>();
this.Error = 0;
}


public ArrayList<GroceryItem> getMilk() {return Milk;}
public void setMilk(ArrayList<GroceryItem> milk) {Milk = milk;}
public ArrayList<GroceryItem> getBread() {return Bread;}
public void setBread(ArrayList<GroceryItem> bread) {Bread = bread;}
public ArrayList<GroceryItem> getCookies() {return Cookies;}
public void setCookies(ArrayList<GroceryItem> cookies) {Cookies = cookies;}
public ArrayList<GroceryItem> getApples() {return Apples;}
public void setApples(ArrayList<GroceryItem> apples) {Apples = apples;}
public int getError() {return Error;}
public void setError(int error) {this.Error = error;}


//create method for count error
}
17 changes: 13 additions & 4 deletions src/main/java/Main.java → src/main/java/JerksonIO.java
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
import org.apache.commons.io.IOUtils;
import java.io.IOException;

public class Main {
public class JerksonIO {



public String readRawDataToString() throws Exception{
ClassLoader classLoader = getClass().getClassLoader();
String result = IOUtils.toString(classLoader.getResourceAsStream("RawData.txt"));
return result;
}

public static String createFormatString() {
return null;
}

public void exportTxt(){

}

public static void main(String[] args) throws Exception{
String output = (new Main()).readRawDataToString();
String output = (new JerksonIO()).readRawDataToString();
System.out.println(output);

}
//tevin was here.
}
169 changes: 169 additions & 0 deletions src/test/java/GroceryItemTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;

public class GroceryItemTest {
String name;
String price;
String type;
String expiration;
GroceryItem groceryItem;
String exp1;
String exp2;
String expSyb1;
String expSyb2;
String expError1;
String expError2;
String expError3;
String expError4;

@Before
public void setup(){
name = "name";
price = "0.00";
type = "food";
expiration = "01-03-2034" ;
exp1 = "nAme:Milk;price:3.23;type:Food;expiration:1/25/2016##";// nor
expSyb1 = "nAMe:cookies;price:3.23?type:Food;expiration:1/26/2016##";// change sy
expSyb2 = "naMe:co0kies;price:0.23@type:Food;expiration:1/26/2019##";// change sy
expError1 = "NaMe:;price:3.25;type:Food;expiration:1/25/2046##"; // error1
expError2 = "NaMe:BRead;price:;type:Food;expiration:1/25/2046##"; // error2
expError3 = "NaMe:cookie;price:3.25;type:Food;expiration:##"; // error3
expError4 = "NaMe:BRead;price:0.45;type:;expiration:1/25/2046##"; // error4
exp2= "NAMe:BRead;price:5.23;type:Food;expiration:4/20/2016##";// nor

// need to set up a constructor.
groceryItem = new GroceryItem(name, price, type , expiration);
// ops
}
// constructor test
@Test
public void constructorTest(){
Assert.assertNotNull(groceryItem);
}

@Test
public void setNameTest(){
groceryItem.setName("cookies");
String actual = groceryItem.getName();
String expected = "cookies";
Assert.assertEquals(expected, actual);
}
// test the obj name


// test the obj price as a string
@Test
public void getPriceTest(){
String actual = groceryItem.getPrice();
String expected = "0.00";
Assert.assertEquals(expected, actual);
}

// test the obj type as a string
@Test
public void getTypeTest(){
String actual = groceryItem.getType();
String expected = "food";
Assert.assertEquals(expected, actual);
}

// test the obj expiration as a string
@Test
public void getExpirationTest(){
String actual = groceryItem.getExpiration();
String expected = "01-03-2034";
Assert.assertEquals(expected, actual);

}
@Test
public void extractNameTest(){


String actual = groceryItem.extractName(exp1);
String expect = "Milk";
Assert.assertEquals(expect,actual);
}
@Test
public void extractName2Test(){


String actual = groceryItem.extractName(exp2);
String expect = "BRead";
Assert.assertEquals(expect,actual);
}

@Test
public void extractPriceTest(){

String actual = groceryItem.extractPrice(exp1);
String expect = "3.23";
Assert.assertEquals(expect,actual);
}
@Test
public void extractPrice2Test(){

String actual = groceryItem.extractPrice(exp2);
String expect = "5.23";
Assert.assertEquals(expect,actual);
}
@Test
public void extractType1Test(){


String actual = groceryItem.extractType(exp1);
String expect = "Food";
Assert.assertEquals(expect,actual);
}
@Test
public void extractType2Test(){


String actual = groceryItem.extractType(exp2);
String expect = "Food";
Assert.assertEquals(expect,actual);
}
@Test
public void extractExpirationTest(){
String actual = groceryItem.extractExpiration(exp1);
String expect = "1/25/2016";
Assert.assertEquals(expect,actual);
}

@Test
public void extractExpiration2Test(){
String actual = groceryItem.extractExpiration(exp2);
String expect = "4/20/2016";
Assert.assertEquals(expect,actual);
}

@Test
public void errorNameTest(){

String actual = groceryItem.extractName(expError1);
String expected = "";
Assert.assertEquals(expected, actual);
}

@Test
public void errorExpirationTest(){
String actual = groceryItem.extractExpiration(expError3);
String expected = "";
Assert.assertEquals(expected, actual);
}

@Test
public void errorTypeTest(){

String actual = groceryItem.extractType(expError4);
String expected = "";
Assert.assertEquals(expected, actual);
}

@Test
public void errorPriceTest2(){
String actual = groceryItem.extractPrice(expError2);
String expected = "";
Assert.assertEquals(expected, actual);
}
}
Loading