From bee8f54440d588d452c9db888aa2f316104c5535 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Sat, 23 Dec 2023 17:26:19 +0100 Subject: [PATCH 01/14] bash: initial impl --- bash/gilded_rose.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100755 bash/gilded_rose.sh diff --git a/bash/gilded_rose.sh b/bash/gilded_rose.sh new file mode 100755 index 00000000..d1d32b34 --- /dev/null +++ b/bash/gilded_rose.sh @@ -0,0 +1,57 @@ +#!/bin/bash + +update_quality() { + local IFS=',' + + while read -r name sell_in_str quality_str; do + declare -i sell_in="$sell_in_str" + declare -i quality="$quality_str" + + if [[ $name != "Aged Brie" && $name != "Backstage passes to a TAFKAL80ETC concert" ]]; then + if ((quality > 0)); then + if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then + ((quality--)) + fi + fi + else + if ((quality < 50)); then + ((quality++)) + + if [[ $name == "Backstage passes to a TAFKAL80ETC concert" ]]; then + if ((sell_in < 11)) && ((quality < 50)); then + ((quality++)) + fi + if ((sell_in < 6)) && ((quality < 50)); then + ((quality++)) + fi + fi + fi + fi + + if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then + ((sell_in--)) + + if ((sell_in < 0)); then + if [[ $name != "Aged Brie" ]]; then + if [[ $name != "Backstage passes to a TAFKAL80ETC concert" ]]; then + if ((quality > 0)); then + if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then + ((quality--)) + fi + fi + else + quality=0 + fi + else + if ((quality < 50)); then + ((quality++)) + fi + fi + fi + fi + + echo "$name,$sell_in,$quality" + done +} + +update_quality From 9039daa7be87e8238fb4528e3c860e151bb46304 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Sat, 23 Dec 2023 17:29:46 +0100 Subject: [PATCH 02/14] . d README.md notes --- bash/README.md | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 bash/README.md diff --git a/bash/README.md b/bash/README.md new file mode 100644 index 00000000..de4024d7 --- /dev/null +++ b/bash/README.md @@ -0,0 +1,10 @@ +A pure "function", so this works: + +```shell +$ echo -e 'Aged Brie,3,5\nOther Item,4,5' |\ + ./gilded_rose.sh |\ + ./gilded_rose.sh |\ + ./gilded_rose.sh +Aged Brie,0,8 +Other Item,1,2 +``` \ No newline at end of file From 56ca5bf41148b63f1b6b6d2e47eff0f0c6da1766 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Sat, 23 Dec 2023 17:56:14 +0100 Subject: [PATCH 03/14] - t verify results --- bash/gilded_rose.sh | 4 ++-- bash/texttest_fixture.sh | 49 ++++++++++++++++++++++++++++++++++++++++ bash/verify.sh | 3 +++ 3 files changed, 54 insertions(+), 2 deletions(-) create mode 100755 bash/texttest_fixture.sh create mode 100755 bash/verify.sh diff --git a/bash/gilded_rose.sh b/bash/gilded_rose.sh index d1d32b34..cf4aef82 100755 --- a/bash/gilded_rose.sh +++ b/bash/gilded_rose.sh @@ -1,7 +1,7 @@ #!/bin/bash update_quality() { - local IFS=',' + local IFS='|' while read -r name sell_in_str quality_str; do declare -i sell_in="$sell_in_str" @@ -50,7 +50,7 @@ update_quality() { fi fi - echo "$name,$sell_in,$quality" + echo "$name|$sell_in|$quality" done } diff --git a/bash/texttest_fixture.sh b/bash/texttest_fixture.sh new file mode 100755 index 00000000..690c9833 --- /dev/null +++ b/bash/texttest_fixture.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +GILDED_ROSE_SCRIPT="./gilded_rose.sh" + +create_initial_items() { + local temp_file=$(mktemp) + + cat <"$temp_file" ++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 +Conjured Mana Cake|3|6 +EOF + + echo "$temp_file" +} + +simulate_days() { + local days=$1 + local items_file=$2 + + for ((day = 0; day <= days; day++)); do + echo "-------- day $day --------" + echo "name, sellIn, quality" + + cat "$items_file" | sed 's/|/, /g' + + local temp_output=$(mktemp) + cat "$items_file" | bash "$GILDED_ROSE_SCRIPT" >"$temp_output" + mv "$temp_output" "$items_file" + + echo "" + done +} + +echo OMGHAI! + +ITEMS_FILE=$(create_initial_items) + +DAYS_TO_SIMULATE=${1:-2} + +simulate_days $DAYS_TO_SIMULATE $ITEMS_FILE + +rm "$ITEMS_FILE" diff --git a/bash/verify.sh b/bash/verify.sh new file mode 100755 index 00000000..561af69d --- /dev/null +++ b/bash/verify.sh @@ -0,0 +1,3 @@ +#!/bin/bash + +./texttest_fixture.sh 30 | diff -u - ../texttests/ThirtyDays/stdout.gr From 4490aaa5fd2cc878732ca12e860c2d60fd20fee7 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Sat, 23 Dec 2023 18:18:38 +0100 Subject: [PATCH 04/14] - t failing unit test --- bash/README.md | 34 ++++++++++++++++++++++++++++++++-- bash/unit_test.sh | 21 +++++++++++++++++++++ bash/verify.sh | 5 ++++- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100755 bash/unit_test.sh diff --git a/bash/README.md b/bash/README.md index de4024d7..07d0d6a7 100644 --- a/bash/README.md +++ b/bash/README.md @@ -1,4 +1,34 @@ -A pure "function", so this works: +# Requirements + +`bash` and friends (`diff`, `grep`, `cat`) + +# (Failing) Unit Test + +```shell +./unit_test.sh +``` + +# Texttest Fixture + +```shell +./texttest_fixture.sh +``` + +Specify days: + +```shell +./texttest_fixture.sh 30 +``` + +Verify againt `ThirtyDays/stdout.gr` + +```shell +./verify.sh +``` + +## BTW + +BTW, the script is a pure "function", so this works: ```shell $ echo -e 'Aged Brie,3,5\nOther Item,4,5' |\ @@ -7,4 +37,4 @@ $ echo -e 'Aged Brie,3,5\nOther Item,4,5' |\ ./gilded_rose.sh Aged Brie,0,8 Other Item,1,2 -``` \ No newline at end of file +``` diff --git a/bash/unit_test.sh b/bash/unit_test.sh new file mode 100755 index 00000000..34cf29d8 --- /dev/null +++ b/bash/unit_test.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +GILDED_ROSE_SCRIPT="./gilded_rose.sh" + +get_name() { + grep -o '^[^|]*' +} + +assert_equals() { + local expected="$1" + diff -u - <(echo "$expected") +} + +test_foo() { + echo "foo|0|0" | + bash "$GILDED_ROSE_SCRIPT" | + get_name | + assert_equals "fixme" +} + +test_foo diff --git a/bash/verify.sh b/bash/verify.sh index 561af69d..ad9d95e5 100755 --- a/bash/verify.sh +++ b/bash/verify.sh @@ -1,3 +1,6 @@ #!/bin/bash -./texttest_fixture.sh 30 | diff -u - ../texttests/ThirtyDays/stdout.gr +./texttest_fixture.sh 30 | + diff -u - ../texttests/ThirtyDays/stdout.gr && + echo "✅ looks good" || + (echo "❌ failed" && exit 1) From 887ad0b60da04e2d40b1ecb53a3c3fd525cb9abb Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Sat, 23 Dec 2023 19:46:03 +0100 Subject: [PATCH 05/14] . d README: update field delimiter --- bash/README.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bash/README.md b/bash/README.md index 07d0d6a7..825e530c 100644 --- a/bash/README.md +++ b/bash/README.md @@ -31,10 +31,10 @@ Verify againt `ThirtyDays/stdout.gr` BTW, the script is a pure "function", so this works: ```shell -$ echo -e 'Aged Brie,3,5\nOther Item,4,5' |\ - ./gilded_rose.sh |\ - ./gilded_rose.sh |\ - ./gilded_rose.sh -Aged Brie,0,8 -Other Item,1,2 +$ echo -e 'Aged Brie|3|5\nOther Item|4|5' | +> ./gilded_rose.sh | +> ./gilded_rose.sh | +> ./gilded_rose.sh +Aged Brie|0|8 +Other Item|1|2 ``` From 7658124173cfa1236200aac26334e60943cc5fbe Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Tue, 26 Dec 2023 12:27:11 +0100 Subject: [PATCH 06/14] gilded_rose.sh: closer to original --- bash/gilded_rose.sh | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-) diff --git a/bash/gilded_rose.sh b/bash/gilded_rose.sh index cf4aef82..e4ce5896 100755 --- a/bash/gilded_rose.sh +++ b/bash/gilded_rose.sh @@ -10,42 +10,46 @@ update_quality() { if [[ $name != "Aged Brie" && $name != "Backstage passes to a TAFKAL80ETC concert" ]]; then if ((quality > 0)); then if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then - ((quality--)) + quality=$((quality - 1)) fi fi else if ((quality < 50)); then - ((quality++)) + quality=$((quality + 1)) if [[ $name == "Backstage passes to a TAFKAL80ETC concert" ]]; then - if ((sell_in < 11)) && ((quality < 50)); then - ((quality++)) + if ((sell_in < 11)); then + if ((quality < 50)); then + quality=$((quality + 1)) + fi fi - if ((sell_in < 6)) && ((quality < 50)); then - ((quality++)) + if ((sell_in < 6)); then + if ((quality < 50)); then + quality=$((quality + 1)) + fi fi fi fi fi if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then - ((sell_in--)) + sell_in=$((sell_in - 1)) + fi - if ((sell_in < 0)); then - if [[ $name != "Aged Brie" ]]; then - if [[ $name != "Backstage passes to a TAFKAL80ETC concert" ]]; then - if ((quality > 0)); then - if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then - ((quality--)) - fi + if ((sell_in < 0)); then + if [[ $name != "Aged Brie" ]]; then + if [[ $name != "Backstage passes to a TAFKAL80ETC concert" ]]; then + if ((quality > 0)); then + if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then + quality=$((quality - 1)) fi - else - quality=0 fi else - if ((quality < 50)); then - ((quality++)) - fi + quality=$((quality - quality)) + fi + else + if ((quality < 50)); then + quality=$((quality + 1)) fi fi fi From 6223bf9919cb0a6794f34af5bb3266f5d4fb11f0 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Tue, 26 Dec 2023 18:09:52 +0100 Subject: [PATCH 07/14] - F more compact --- bash/gilded_rose.sh | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/bash/gilded_rose.sh b/bash/gilded_rose.sh index e4ce5896..4b723399 100755 --- a/bash/gilded_rose.sh +++ b/bash/gilded_rose.sh @@ -3,10 +3,7 @@ update_quality() { local IFS='|' - while read -r name sell_in_str quality_str; do - declare -i sell_in="$sell_in_str" - declare -i quality="$quality_str" - + while read -r name sell_in quality; do if [[ $name != "Aged Brie" && $name != "Backstage passes to a TAFKAL80ETC concert" ]]; then if ((quality > 0)); then if [[ $name != "Sulfuras, Hand of Ragnaros" ]]; then From dc652d4d091098367f78c4dfbf6aef101cc06bf8 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Fri, 5 Jan 2024 09:11:27 +0100 Subject: [PATCH 08/14] . t bash/texttest_fixture.sh temp file -> variable --- bash/texttest_fixture.sh | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) diff --git a/bash/texttest_fixture.sh b/bash/texttest_fixture.sh index 690c9833..7018f127 100755 --- a/bash/texttest_fixture.sh +++ b/bash/texttest_fixture.sh @@ -2,11 +2,8 @@ GILDED_ROSE_SCRIPT="./gilded_rose.sh" -create_initial_items() { - local temp_file=$(mktemp) - - cat <"$temp_file" -+5 Dexterity Vest|10|20 +# Define initial items as a multi-line string +initial_items="+5 Dexterity Vest|10|20 Aged Brie|2|0 Elixir of the Mongoose|5|7 Sulfuras, Hand of Ragnaros|0|80 @@ -14,25 +11,20 @@ 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 -Conjured Mana Cake|3|6 -EOF - - echo "$temp_file" -} +Conjured Mana Cake|3|6" simulate_days() { local days=$1 - local items_file=$2 + local items="$2" for ((day = 0; day <= days; day++)); do echo "-------- day $day --------" echo "name, sellIn, quality" - cat "$items_file" | sed 's/|/, /g' + echo "$items" | sed 's/|/, /g' - local temp_output=$(mktemp) - cat "$items_file" | bash "$GILDED_ROSE_SCRIPT" >"$temp_output" - mv "$temp_output" "$items_file" + # Update the items for the next day + items=$(echo "$items" | bash "$GILDED_ROSE_SCRIPT") echo "" done @@ -40,10 +32,6 @@ simulate_days() { echo OMGHAI! -ITEMS_FILE=$(create_initial_items) - DAYS_TO_SIMULATE=${1:-2} -simulate_days $DAYS_TO_SIMULATE $ITEMS_FILE - -rm "$ITEMS_FILE" +simulate_days $DAYS_TO_SIMULATE "$initial_items" From d5b430fde96245fedab5a012643552234026ed81 Mon Sep 17 00:00:00 2001 From: Nitsan Avni Date: Fri, 5 Jan 2024 09:21:12 +0100 Subject: [PATCH 09/14] - r jq: jaq -> jq, rm foreach --- jq/README.md | 8 ++-- jq/gilded-rose.jq | 92 +++++++++++++++++++++--------------------- jq/test-gilded-rose.sh | 2 +- jq/texttest_fixture.jq | 2 +- 4 files changed, 51 insertions(+), 53 deletions(-) diff --git a/jq/README.md b/jq/README.md index a4dd4d82..1e823968 100644 --- a/jq/README.md +++ b/jq/README.md @@ -1,6 +1,6 @@ -# Installs +# Requirements -[install jaq](https://github.com/01mf02/jaq#installation) (latest development version) +jq # Failing Unit Test @@ -11,11 +11,11 @@ # TextTest Fixture ```shell -jaq -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)" +jq -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)" ``` Specify days (e.g. 10 days): ```shell -jaq --arg days 10 -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)" +jq --arg days 10 -nr "$(cat gilded-rose.jq) $(cat texttest_fixture.jq)" ``` diff --git a/jq/gilded-rose.jq b/jq/gilded-rose.jq index e4096d57..e9c7d941 100644 --- a/jq/gilded-rose.jq +++ b/jq/gilded-rose.jq @@ -1,54 +1,52 @@ def update_quality: [ - foreach .[] as $item ( - null; - $item | - if .name != "Aged Brie" and .name != "Backstage passes to a TAFKAL80ETC concert" then - if .quality > 0 then - if .name != "Sulfuras, Hand of Ragnaros" then - .quality = .quality - 1 - else . end - else . end + .[] + | + if .name != "Aged Brie" and .name != "Backstage passes to a TAFKAL80ETC concert" then + if .quality > 0 then + if .name != "Sulfuras, Hand of Ragnaros" then + .quality = .quality - 1 + end + end + else + if .quality < 50 then + .quality = .quality + 1 + | + if .name == "Backstage passes to a TAFKAL80ETC concert" then + if .sell_in < 11 then + if .quality < 50 then + .quality = .quality + 1 + end + end + | + if .sell_in < 6 then + if .quality < 50 then + .quality = .quality + 1 + end + end + end + end + end + | + if .name != "Sulfuras, Hand of Ragnaros" then + .sell_in = .sell_in - 1 + end + | + if .sell_in < 0 then + if .name != "Aged Brie" then + if .name != "Backstage passes to a TAFKAL80ETC concert" then + if .quality > 0 then + if .name != "Sulfuras, Hand of Ragnaros" then + .quality = .quality - 1 + end + end + else + .quality = .quality - .quality + end else if .quality < 50 then .quality = .quality + 1 - | - if .name == "Backstage passes to a TAFKAL80ETC concert" then - if .sell_in < 11 then - if .quality < 50 then - .quality = .quality + 1 - else . end - else . end - | - if .sell_in < 6 then - if .quality < 50 then - .quality = .quality + 1 - else . end - else . end - else . end - else . end - end - | - if .name != "Sulfuras, Hand of Ragnaros" then - .sell_in = .sell_in - 1 - else . end - | - if .sell_in < 0 then - if .name != "Aged Brie" then - if .name != "Backstage passes to a TAFKAL80ETC concert" then - if .quality > 0 then - if .name != "Sulfuras, Hand of Ragnaros" then - .quality = .quality - 1 - else . end - else . end - else - .quality = .quality - .quality - end - else - if .quality < 50 then - .quality = .quality + 1 - else . end end - else . end - ) + end + end ]; diff --git a/jq/test-gilded-rose.sh b/jq/test-gilded-rose.sh index 62d91240..b667d26f 100755 --- a/jq/test-gilded-rose.sh +++ b/jq/test-gilded-rose.sh @@ -1,3 +1,3 @@ #!/usr/bin/env bash -jaq -en "$(cat gilded-rose.jq)"'[{name:"foo",sell_in:0,quality:0}] | update_quality | .[].name == "fixme"' +jq -en "$(cat gilded-rose.jq)"'[{name:"foo",sell_in:0,quality:0}] | update_quality | .[].name == "fixme"' diff --git a/jq/texttest_fixture.jq b/jq/texttest_fixture.jq index 12c08dc3..9f153790 100644 --- a/jq/texttest_fixture.jq +++ b/jq/texttest_fixture.jq @@ -12,7 +12,7 @@ { name: "Conjured Mana Cake", sell_in: 3, quality: 6} # <-- :O ] | { items: ., day: 0 } | - recurse(.day += 1 | .items = (.items | update_quality); .day < ($ARGS.named.days // 2 | tonumber)) | + recurse(.day += 1 | .items = (.items | update_quality); .day <= ($ARGS.named.days // 2 | tonumber)) | ( (["-------- day ", (.day | tostring), " --------"] | add), ("name, sellIn, quality"), From 1bbc3b408ab1734bf148f4821bb02b6db178f2d5 Mon Sep 17 00:00:00 2001 From: Bronson McNaughton Date: Sun, 7 Jan 2024 12:09:21 +1300 Subject: [PATCH 10/14] doc - update command to run ruby tests --- ruby/README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ruby/README.md b/ruby/README.md index 731dfcaa..ffbd4914 100644 --- a/ruby/README.md +++ b/ruby/README.md @@ -10,7 +10,7 @@ Ensure you have RSpec installed gem install rspec ``` -ruby gilded_rose_spec.rb +rspec gilded_rose_spec.rb ``` ## Run the TextTest fixture from the Command-Line From 70ca9b956994f7cfb34e975df61e529ff20505b1 Mon Sep 17 00:00:00 2001 From: Cp shivhare Date: Fri, 22 Dec 2023 20:35:18 +0530 Subject: [PATCH 11/14] Made runnable for ruby --- texttests/config.gr | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/texttests/config.gr b/texttests/config.gr index 7eb0a5f0..2cb021dd 100755 --- a/texttests/config.gr +++ b/texttests/config.gr @@ -28,8 +28,8 @@ diff_program:meld #interpreter:python # Settings for the Ruby version -#executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb -#interpreter:ruby +executable:${TEXTTEST_HOME}/ruby/texttest_fixture.rb +interpreter:ruby # Settings for the C# Core version #executable:${TEXTTEST_HOME}/csharpcore/GildedRoseTests/bin/Debug/net7.0/GildedRoseTests From 24c9a7f603b4b022fa99950d7b2dae8fa4ee3e44 Mon Sep 17 00:00:00 2001 From: Cp shivhare Date: Fri, 22 Dec 2023 20:35:44 +0530 Subject: [PATCH 12/14] Fixed and add minitest --- ruby/gilded_rose_tests.rb | 74 ++++++++++++++++++++++++++++++++++----- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/ruby/gilded_rose_tests.rb b/ruby/gilded_rose_tests.rb index 2e1b70d1..b7643d3e 100644 --- a/ruby/gilded_rose_tests.rb +++ b/ruby/gilded_rose_tests.rb @@ -1,12 +1,68 @@ -require File.join(File.dirname(__FILE__), 'gilded_rose') -require 'test/unit' +require 'minitest/autorun' +require_relative 'gilded_rose' -class TestUntitled < Test::Unit::TestCase - - def test_foo - items = [Item.new("foo", 0, 0)] - GildedRose.new(items).update_quality() - assert_equal items[0].name, "fixme" +class TestGildedRose < Minitest::Test + def test_update_quality_regular_item + item = Item.new('Regular Item', 5, 10) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 9, item.quality + assert_equal 4, item.sell_in end -end \ No newline at end of file + def test_update_quality_negative_sell_in_regular_item + item = Item.new('Regular Item', 0, 10) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 8, item.quality + end + + def test_update_quality_aged_brie + item = Item.new('Aged Brie', 5, 10) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 11, item.quality + end + + def test_update_quality_max_quality_aged_brie + item = Item.new('Aged Brie', 5, 50) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 50, item.quality + end + + def test_update_quality_backstage_passes_approaching + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 11, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 21, item.quality + end + + def test_update_quality_backstage_passes_sell_in_10_or_less + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 10, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 22, item.quality + end + + def test_update_quality_backstage_passes_sell_in_5_or_less + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 5, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 23, item.quality + end + + def test_update_quality_backstage_passes_after_concert + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 0, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 0, item.quality + end + + def test_update_quality_sulfuras + item = Item.new('Sulfuras, Hand of Ragnaros', 5, 80) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + assert_equal 80, item.quality + end +end From 92a459442afe49ad7e1d4f86d4b1c5c9dbcdf1e7 Mon Sep 17 00:00:00 2001 From: Cp shivhare Date: Fri, 22 Dec 2023 20:36:03 +0530 Subject: [PATCH 13/14] Fixed and add rspec --- ruby/gilded_rose_spec.rb | 68 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 67 insertions(+), 1 deletion(-) diff --git a/ruby/gilded_rose_spec.rb b/ruby/gilded_rose_spec.rb index 269fe1b0..1ad468f8 100644 --- a/ruby/gilded_rose_spec.rb +++ b/ruby/gilded_rose_spec.rb @@ -1,3 +1,5 @@ +require 'rspec' + require File.join(File.dirname(__FILE__), 'gilded_rose') describe GildedRose do @@ -6,7 +8,71 @@ describe GildedRose do it "does not change the name" do items = [Item.new("foo", 0, 0)] GildedRose.new(items).update_quality() - expect(items[0].name).to eq "fixme" + expect(items[0].name).to eq "foo" + end + + it 'decreases the sell_in and quality for regular items' do + item = Item.new('Regular Item', 5, 10) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(9) + expect(item.sell_in).to eq(4) + end + + it 'decreases quality twice as fast when sell_in is negative for regular items' do + item = Item.new('Regular Item', 0, 10) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(8) + end + + it 'increases the quality of Aged Brie' do + item = Item.new('Aged Brie', 5, 10) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(11) + end + + it 'does not increase the quality of Aged Brie beyond 50' do + item = Item.new('Aged Brie', 5, 50) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(50) + end + + it 'increases the quality of Backstage passes as sell_in approaches' do + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 11, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(21) + end + + it 'increases the quality of Backstage passes by 2 when sell_in is 10 or less' do + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 10, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(22) + end + + it 'increases the quality of Backstage passes by 3 when sell_in is 5 or less' do + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 5, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(23) + end + + it 'sets the quality of Backstage passes to 0 after the concert' do + item = Item.new('Backstage passes to a TAFKAL80ETC concert', 0, 20) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(0) + end + + it 'does not decrease the quality of Sulfuras' do + item = Item.new('Sulfuras, Hand of Ragnaros', 5, 80) + gilded_rose = GildedRose.new([item]) + gilded_rose.update_quality + expect(item.quality).to eq(80) end end From e43a1a270f3da711669e679ef7085f8e6ff4c651 Mon Sep 17 00:00:00 2001 From: Peter Kofler Date: Wed, 17 Jan 2024 20:12:19 +0100 Subject: [PATCH 14/14] Replace complete tests with sample tests. --- ruby/gilded_rose_spec.rb | 76 +++------------------------------------ ruby/gilded_rose_tests.rb | 66 +++------------------------------- 2 files changed, 8 insertions(+), 134 deletions(-) diff --git a/ruby/gilded_rose_spec.rb b/ruby/gilded_rose_spec.rb index 1ad468f8..015a759f 100644 --- a/ruby/gilded_rose_spec.rb +++ b/ruby/gilded_rose_spec.rb @@ -3,77 +3,9 @@ require 'rspec' require File.join(File.dirname(__FILE__), 'gilded_rose') describe GildedRose do - - describe "#update_quality" do - it "does not change the name" do - items = [Item.new("foo", 0, 0)] - GildedRose.new(items).update_quality() - expect(items[0].name).to eq "foo" - end - - it 'decreases the sell_in and quality for regular items' do - item = Item.new('Regular Item', 5, 10) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(9) - expect(item.sell_in).to eq(4) - end - - it 'decreases quality twice as fast when sell_in is negative for regular items' do - item = Item.new('Regular Item', 0, 10) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(8) - end - - it 'increases the quality of Aged Brie' do - item = Item.new('Aged Brie', 5, 10) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(11) - end - - it 'does not increase the quality of Aged Brie beyond 50' do - item = Item.new('Aged Brie', 5, 50) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(50) - end - - it 'increases the quality of Backstage passes as sell_in approaches' do - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 11, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(21) - end - - it 'increases the quality of Backstage passes by 2 when sell_in is 10 or less' do - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 10, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(22) - end - - it 'increases the quality of Backstage passes by 3 when sell_in is 5 or less' do - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 5, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(23) - end - - it 'sets the quality of Backstage passes to 0 after the concert' do - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 0, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(0) - end - - it 'does not decrease the quality of Sulfuras' do - item = Item.new('Sulfuras, Hand of Ragnaros', 5, 80) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - expect(item.quality).to eq(80) - end + it "does not change the name" do + items = [Item.new("foo", 0, 0)] + GildedRose.new(items).update_quality() + expect(items[0].name).to eq "fixme" end - end diff --git a/ruby/gilded_rose_tests.rb b/ruby/gilded_rose_tests.rb index b7643d3e..4e2ec30d 100644 --- a/ruby/gilded_rose_tests.rb +++ b/ruby/gilded_rose_tests.rb @@ -2,67 +2,9 @@ require 'minitest/autorun' require_relative 'gilded_rose' class TestGildedRose < Minitest::Test - def test_update_quality_regular_item - item = Item.new('Regular Item', 5, 10) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 9, item.quality - assert_equal 4, item.sell_in - end - - def test_update_quality_negative_sell_in_regular_item - item = Item.new('Regular Item', 0, 10) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 8, item.quality - end - - def test_update_quality_aged_brie - item = Item.new('Aged Brie', 5, 10) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 11, item.quality - end - - def test_update_quality_max_quality_aged_brie - item = Item.new('Aged Brie', 5, 50) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 50, item.quality - end - - def test_update_quality_backstage_passes_approaching - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 11, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 21, item.quality - end - - def test_update_quality_backstage_passes_sell_in_10_or_less - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 10, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 22, item.quality - end - - def test_update_quality_backstage_passes_sell_in_5_or_less - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 5, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 23, item.quality - end - - def test_update_quality_backstage_passes_after_concert - item = Item.new('Backstage passes to a TAFKAL80ETC concert', 0, 20) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 0, item.quality - end - - def test_update_quality_sulfuras - item = Item.new('Sulfuras, Hand of Ragnaros', 5, 80) - gilded_rose = GildedRose.new([item]) - gilded_rose.update_quality - assert_equal 80, item.quality + def test_foo + items = [Item.new("foo", 0, 0)] + GildedRose.new(items).update_quality() + assert_equal "fixme", items[0].name end end