mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
commit
0fa2c2e623
21
jq/README.md
Normal file
21
jq/README.md
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# Installs
|
||||||
|
|
||||||
|
[install jaq](https://github.com/01mf02/jaq#installation) (latest development version)
|
||||||
|
|
||||||
|
# Failing Unit Test
|
||||||
|
|
||||||
|
```shell
|
||||||
|
./test-gilded-rose.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
# TextTest Fixture
|
||||||
|
|
||||||
|
```shell
|
||||||
|
jaq -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)"
|
||||||
|
```
|
||||||
54
jq/gilded-rose.jq
Normal file
54
jq/gilded-rose.jq
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
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
|
||||||
|
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
|
||||||
|
)
|
||||||
|
];
|
||||||
3
jq/test-gilded-rose.sh
Executable file
3
jq/test-gilded-rose.sh
Executable file
@ -0,0 +1,3 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
jaq -en "$(cat gilded-rose.jq)"'[{name:"foo",sell_in:0,quality:0}] | update_quality | .[].name == "fixme"'
|
||||||
22
jq/texttest_fixture.jq
Normal file
22
jq/texttest_fixture.jq
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
"OMGHAI!",
|
||||||
|
(
|
||||||
|
[
|
||||||
|
{ name: "+5 Dexterity Vest", sell_in: 10, quality: 20 },
|
||||||
|
{ name: "Aged Brie", sell_in: 2, quality: 0 },
|
||||||
|
{ name: "Elixir of the Mongoose", sell_in: 5, quality: 7 },
|
||||||
|
{ name: "Sulfuras, Hand of Ragnaros", sell_in: 0, quality: 80 },
|
||||||
|
{ name: "Sulfuras, Hand of Ragnaros", sell_in: 1, quality: 80 },
|
||||||
|
{ name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 15, quality: 20 },
|
||||||
|
{ name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 10, quality: 49 },
|
||||||
|
{ name: "Backstage passes to a TAFKAL80ETC concert", sell_in: 5, quality: 49 },
|
||||||
|
{ 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)) |
|
||||||
|
(
|
||||||
|
"",
|
||||||
|
(["-------- day ", (.day | tostring), " --------"] | add),
|
||||||
|
("name, sellIn, quality"),
|
||||||
|
(.items[] | [.name, .sell_in, .quality | tostring] | join(", "))
|
||||||
|
)
|
||||||
|
)
|
||||||
Loading…
Reference in New Issue
Block a user