From 9c8577e6578be0e9ea1f4c48a239e7fe817d49ad Mon Sep 17 00:00:00 2001 From: King Tran Date: Wed, 27 Apr 2022 17:41:19 +0700 Subject: [PATCH] Export category test to csv and add base test result --- Java/base-output.csv | 55 +++++++++++++++++++ .../java/com/gildedrose/TexttestFixture.java | 51 +++++++++++------ 2 files changed, 90 insertions(+), 16 deletions(-) create mode 100644 Java/base-output.csv diff --git a/Java/base-output.csv b/Java/base-output.csv new file mode 100644 index 00000000..f90b5125 --- /dev/null +++ b/Java/base-output.csv @@ -0,0 +1,55 @@ +name, sellIn, quality +-------- day 0 -------- ++5 Dexterity Vest, 10, 20 +Aged Brie, 2, 0 +Elixir of the Mongoose, 5, 7 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 15, 20 +Backstage passes to a TAFKAL80ETC concert, 10, 49 +Backstage passes to a TAFKAL80ETC concert, 5, 49 +-------- day 1 -------- ++5 Dexterity Vest, 9, 19 +Aged Brie, 1, 1 +Elixir of the Mongoose, 4, 6 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 14, 21 +Backstage passes to a TAFKAL80ETC concert, 9, 50 +Backstage passes to a TAFKAL80ETC concert, 4, 50 +-------- day 2 -------- ++5 Dexterity Vest, 8, 18 +Aged Brie, 0, 2 +Elixir of the Mongoose, 3, 5 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 13, 22 +Backstage passes to a TAFKAL80ETC concert, 8, 50 +Backstage passes to a TAFKAL80ETC concert, 3, 50 +-------- day 3 -------- ++5 Dexterity Vest, 7, 17 +Aged Brie, -1, 4 +Elixir of the Mongoose, 2, 4 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 12, 23 +Backstage passes to a TAFKAL80ETC concert, 7, 50 +Backstage passes to a TAFKAL80ETC concert, 2, 50 +-------- day 4 -------- ++5 Dexterity Vest, 6, 16 +Aged Brie, -2, 6 +Elixir of the Mongoose, 1, 3 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 11, 24 +Backstage passes to a TAFKAL80ETC concert, 6, 50 +Backstage passes to a TAFKAL80ETC concert, 1, 50 +-------- day 5 -------- ++5 Dexterity Vest, 5, 15 +Aged Brie, -3, 8 +Elixir of the Mongoose, 0, 2 +Sulfuras, Hand of Ragnaros, 0, 80 +Sulfuras, Hand of Ragnaros, -1, 80 +Backstage passes to a TAFKAL80ETC concert, 10, 25 +Backstage passes to a TAFKAL80ETC concert, 5, 50 +Backstage passes to a TAFKAL80ETC concert, 0, 50 diff --git a/Java/src/test/java/com/gildedrose/TexttestFixture.java b/Java/src/test/java/com/gildedrose/TexttestFixture.java index d059c88f..e56ee114 100644 --- a/Java/src/test/java/com/gildedrose/TexttestFixture.java +++ b/Java/src/test/java/com/gildedrose/TexttestFixture.java @@ -1,37 +1,56 @@ package com.gildedrose; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.PrintWriter; +import java.util.ArrayList; +import java.util.List; + public class TexttestFixture { public static void main(String[] args) { System.out.println("OMGHAI!"); - Item[] items = new Item[] { - new Item("+5 Dexterity Vest", 10, 20), // - new Item("Aged Brie", 2, 0), // - new Item("Elixir of the Mongoose", 5, 7), // - new Item("Sulfuras, Hand of Ragnaros", 0, 80), // - new Item("Sulfuras, Hand of Ragnaros", -1, 80), - new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), - new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), - new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), - // this conjured item does not work properly yet - new Item("Conjured Mana Cake", 3, 6) }; + Item[] items = new Item[]{ + new Item("+5 Dexterity Vest", 10, 20), // + new Item("Aged Brie", 2, 0), // + new Item("Elixir of the Mongoose", 5, 7), // + new Item("Sulfuras, Hand of Ragnaros", 0, 80), // + new Item("Sulfuras, Hand of Ragnaros", -1, 80), + new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), + new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), + new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), + // this conjured item does not work properly yet +// new Item("Conjured Mana Cake", 3, 6) + }; GildedRose app = new GildedRose(items); - int days = 2; + int days = 6; if (args.length > 0) { days = Integer.parseInt(args[0]) + 1; } + List output = new ArrayList<>(); + output.add("name, sellIn, quality"); for (int i = 0; i < days; i++) { - System.out.println("-------- day " + i + " --------"); - System.out.println("name, sellIn, quality"); + output.add("-------- day " + i + " --------"); for (Item item : items) { - System.out.println(item); + output.add(item.toString()); } - System.out.println(); app.updateQuality(); } + try { + exportToCsv(output, "base-output.csv"); + } catch (FileNotFoundException e) { + throw new RuntimeException(e); + } + } + + private static void exportToCsv(List data, String fileName) throws FileNotFoundException { + File csvOutputFile = new File(fileName); + try (PrintWriter pw = new PrintWriter(csvOutputFile)) { + data.forEach(pw::println); + } } }