From d73f9610896869440ceff39adaca3caae42cf398 Mon Sep 17 00:00:00 2001 From: Sasha Schwartz Date: Sat, 3 May 2025 14:14:25 -0500 Subject: [PATCH] separate files based on feedback --- odin/README.md | 6 +-- .../main.odin => src/core/gilded_rose.odin} | 43 ----------------- odin/src/main.odin | 46 +++++++++++++++++++ odin/tests/gilded_rose_test.odin | 2 +- texttests/config.gr | 2 +- 5 files changed, 51 insertions(+), 48 deletions(-) rename odin/{gilded_rose/main.odin => src/core/gilded_rose.odin} (54%) create mode 100644 odin/src/main.odin diff --git a/odin/README.md b/odin/README.md index 92e596ec..af878cfc 100644 --- a/odin/README.md +++ b/odin/README.md @@ -7,10 +7,10 @@ Learn how to install Odin on your system [here](https://odin-lang.org/docs/insta $ odin test tests ``` ## Run the TextTest fixture on the command line -Build and install the executable +Build the executable: ``` -$ odin build gilded_rose +$ odin build src -out:gilded_rose ``` Execute it on the command line with an argument for the number of days: @@ -30,5 +30,5 @@ $ ./gilded_rose.exe 10 There are instructions in the TextTest Readme for setting up TextTest. You will need to specify the executable in `config.gr`. Uncomment this line to use it: ``` -#executable:${TEXTTEST_HOME}/odin/gilded_rose(include your OS executable extension here) +#executable:${TEXTTEST_HOME}/odin/gilded_rose ``` diff --git a/odin/gilded_rose/main.odin b/odin/src/core/gilded_rose.odin similarity index 54% rename from odin/gilded_rose/main.odin rename to odin/src/core/gilded_rose.odin index cd603525..35ce6cfc 100644 --- a/odin/gilded_rose/main.odin +++ b/odin/src/core/gilded_rose.odin @@ -1,9 +1,5 @@ package gilded_rose -import "core:fmt" -import "core:os" -import "core:strconv" - Item :: struct { name: string, sell_in: i32, @@ -57,42 +53,3 @@ update_quality :: proc(inventory: []Item) { } } } - -main :: proc() { - days := 2 - if len(os.args) >= 2 { - if val, ok := strconv.parse_int(os.args[1]); ok && val > 0 { - days = val - } else { - fmt.eprintf("Please enter a number greater than 0\n") - return - } - } - - items := []Item { - {"+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}, - // This Conjured item does not work properly yet - {"Conjured Mana Cake", 3, 6}, - } - - fmt.println("OMGHAI!") - - for day in 0 ..= days { - day_line := fmt.tprint("-------- day", day, "--------") - fmt.println(day_line) - fmt.println("name, sellIn, quality") - for item in items { - item_line := fmt.tprint(item.name, item.sell_in, item.quality, sep = ", ") - fmt.println(item_line) - } - fmt.println() - update_quality(items) - } -} diff --git a/odin/src/main.odin b/odin/src/main.odin new file mode 100644 index 00000000..904f5b1d --- /dev/null +++ b/odin/src/main.odin @@ -0,0 +1,46 @@ +package main + +import GildedRose "./core" +import "core:fmt" +import "core:os" +import "core:slice" +import "core:strconv" + +main :: proc() { + days := 2 + if num_of_days, arg_ok := slice.get(os.args, 1); arg_ok { + if val, ok := strconv.parse_int(num_of_days); ok && val > 0 { + days = val + } else { + fmt.eprintf("Please enter a number greater than 0\n") + return + } + } + + items := []GildedRose.Item { + {"+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}, + // This Conjured item does not work properly yet + {"Conjured Mana Cake", 3, 6}, + } + + fmt.println("OMGHAI!") + + for day in 0 ..= days { + day_line := fmt.tprint("-------- day", day, "--------") + fmt.println(day_line) + fmt.println("name, sellIn, quality") + for item in items { + item_line := fmt.tprint(item.name, item.sell_in, item.quality, sep = ", ") + fmt.println(item_line) + } + fmt.println() + GildedRose.update_quality(items) + } +} diff --git a/odin/tests/gilded_rose_test.odin b/odin/tests/gilded_rose_test.odin index cdbc1e4b..c24ff7dd 100644 --- a/odin/tests/gilded_rose_test.odin +++ b/odin/tests/gilded_rose_test.odin @@ -1,6 +1,6 @@ package test_gilded_rose -import GildedRose "../gilded_rose" +import GildedRose "../src/core" import "core:testing" @(test) diff --git a/texttests/config.gr b/texttests/config.gr index 6972127e..9c707ffc 100755 --- a/texttests/config.gr +++ b/texttests/config.gr @@ -65,6 +65,6 @@ interpreter:ruby # executable:${TEXTTEST_HOME}/ocaml/_build/default/bin/main.exe # Settings for the Odin version -#executable:${TEXTTEST_HOME}/odin/gilded_rose(include your OS executable extension here) +#executable:${TEXTTEST_HOME}/odin/gilded_rose filename_convention_scheme:standard