diff options
author | j-james | 2022-10-17 06:25:45 +0000 |
---|---|---|
committer | j-james | 2022-10-17 06:27:55 +0000 |
commit | 3e9bb5fae16c35938bc1f7f7669c12cc355c9331 (patch) | |
tree | 82e1ab837579e7762071ea97c064c0750a38c106 /src/test | |
parent | 0845be5ec0215fb43f9dbdef00b22a733d4080b3 (diff) |
Basic prototypes of HTML/CSS lexers
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/model/CssLexerTest.java | 67 | ||||
-rw-r--r-- | src/test/model/HtmlLexerTest.java | 69 | ||||
-rw-r--r-- | src/test/model/MyModelTest.java | 7 |
3 files changed, 136 insertions, 7 deletions
diff --git a/src/test/model/CssLexerTest.java b/src/test/model/CssLexerTest.java new file mode 100644 index 0000000..4ed28e2 --- /dev/null +++ b/src/test/model/CssLexerTest.java @@ -0,0 +1,67 @@ +package model; + +import model.css.CssLexer; +import org.junit.jupiter.api.Test; + +import java.io.IOException; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class CssLexerTest { + + @Test + void testIdiomaticHtml() { + try { + String idiomaticCss = Files.readString(Path.of("data/example.css")); + String[] expected = {"body", "{", "background-color", ":", "#f0f0f2", ";", "margin", ":", "0", ";", "padding", ":", "0", ";", "font-family", ":", "-apple-system,", "system-ui,", "BlinkMacSystemFont,", "\"Segoe UI\",", "\"Open Sans\",", "\"Helvetica Neue\",", "Helvetica,", "Arial,", "sans-serif", ";", "}", "div", "{", "width", ":", "600px", ";", "margin", ":", "5em", "auto", ";", "padding", ":", "2em", ";", "background-color", ":", "#fdfdff", ";", "border-radius", ":", "0.5em", ";", "box-shadow", ":", "2px", "3px", "7px", "2px", "rgba(0,0,0,0.02)", ";", "}", "a", ":", "link,", "a", ":", "visited", "{", "color", ":", "#38488f", ";", "text-decoration", ":", "none", ";", "}", "@media", "(max-width", ":", "700px)", "{", "div", "{", "margin", ":", "0", "auto", ";", "width", ":", "auto", ";", "}", "}"}; + + assertEquals(CssLexer.lex(idiomaticCss), Arrays.asList(expected)); + for (String i : CssLexer.lex(idiomaticCss)) { + System.out.print("\""); + System.out.print(i); + System.out.print("\", "); + } + } catch (IOException e) { + System.out.printf("fuck %s\n", e.toString()); + System.out.println(System.getProperty("user.dir")); + } + } +/** + FoodServicesCard c1; + FoodServicesCard c2; + FoodServicesCard c3; + + @BeforeEach + void runBefore() { + c1 = new FoodServicesCard(0); + c2 = new FoodServicesCard(100); + c3 = new FoodServicesCard(2000); + } + + @Test + void testReloadingAndPurchasing() { + assertFalse(c1.makePurchase(100)); + assertEquals(c1.getBalance(), 0); + c2.reload(10); + assertEquals(c2.getBalance(), 110); + assertTrue(c3.makePurchase(1400)); + assertEquals(c3.getBalance(), 600); + } + + @Test + void testRewardPoints() { + if (c1.makePurchase(c1.POINTS_NEEDED_FOR_CASH_BACK / 2)) { + assertEquals(c1.getRewardPoints(), (c1.POINTS_NEEDED_FOR_CASH_BACK / 2)); + } else { + assertEquals(c1.getRewardPoints(), 0); + } + c2.makePurchase(c2.POINTS_NEEDED_FOR_CASH_BACK); + assertEquals(c2.getRewardPoints(), 0); + c3.makePurchase(1200); + assertEquals(c3.getRewardPoints(), 1200 % c3.POINTS_NEEDED_FOR_CASH_BACK); + } + */ +}
\ No newline at end of file diff --git a/src/test/model/HtmlLexerTest.java b/src/test/model/HtmlLexerTest.java new file mode 100644 index 0000000..9dd5574 --- /dev/null +++ b/src/test/model/HtmlLexerTest.java @@ -0,0 +1,69 @@ +package model; + +import model.html.HtmlLexer; + +import org.junit.jupiter.api.*; + +import java.util.Arrays; + +import static org.junit.jupiter.api.Assertions.*; + +class HtmlLexerTest { + String idiomaticHtml = "<!DOCTYPE html><html><head></head><body><p>Hello,world!</p></body></html>"; + String brokenHtml = "<html><foo><bar></bar><ba"; + String trailingTextHtml = "<html><foo><bar></bar>ba"; + + @Test + void testIdiomaticHtml() { + String[] idiomaticHtmlArray = {"<!DOCTYPE html>","<html>","<head>","</head>","<body>","<p>","Hello,world!","</p>","</body>","</html>"}; + assertEquals(HtmlLexer.lex(idiomaticHtml), Arrays.asList(idiomaticHtmlArray)); + } + + @Test + void testBrokenHtml() { + String[] brokenHtmlArray = {"<html>","<foo>","<bar>","</bar>","<ba>"}; + assertEquals(HtmlLexer.lex(brokenHtml), Arrays.asList(brokenHtmlArray)); + } + + @Test + void testTrailingTextHtml() { + String[] trailingTextHtmlArray = {"<html>","<foo>","<bar>","</bar>","ba"}; + assertEquals(HtmlLexer.lex(trailingTextHtml), Arrays.asList(trailingTextHtmlArray)); + } + +/** + FoodServicesCard c1; + FoodServicesCard c2; + FoodServicesCard c3; + + @BeforeEach + void runBefore() { + c1 = new FoodServicesCard(0); + c2 = new FoodServicesCard(100); + c3 = new FoodServicesCard(2000); + } + + @Test + void testReloadingAndPurchasing() { + assertFalse(c1.makePurchase(100)); + assertEquals(c1.getBalance(), 0); + c2.reload(10); + assertEquals(c2.getBalance(), 110); + assertTrue(c3.makePurchase(1400)); + assertEquals(c3.getBalance(), 600); + } + + @Test + void testRewardPoints() { + if (c1.makePurchase(c1.POINTS_NEEDED_FOR_CASH_BACK / 2)) { + assertEquals(c1.getRewardPoints(), (c1.POINTS_NEEDED_FOR_CASH_BACK / 2)); + } else { + assertEquals(c1.getRewardPoints(), 0); + } + c2.makePurchase(c2.POINTS_NEEDED_FOR_CASH_BACK); + assertEquals(c2.getRewardPoints(), 0); + c3.makePurchase(1200); + assertEquals(c3.getRewardPoints(), 1200 % c3.POINTS_NEEDED_FOR_CASH_BACK); + } + */ +}
\ No newline at end of file diff --git a/src/test/model/MyModelTest.java b/src/test/model/MyModelTest.java deleted file mode 100644 index c41f32e..0000000 --- a/src/test/model/MyModelTest.java +++ /dev/null @@ -1,7 +0,0 @@ -package model; - -import static org.junit.jupiter.api.Assertions.*; - -class MyModelTest { - // delete or rename this class! -}
\ No newline at end of file |