GildedRose-Refactoring-Kata icon indicating copy to clipboard operation
GildedRose-Refactoring-Kata copied to clipboard

Gilded rose in Nim

Open TinBryn opened this issue 4 years ago • 1 comments

It may be interesting to see how this is refactored in Nim. Particularly I'd be interested to see if anyone gets it to the point of being able to write a macro.

It doesn't have support for texttest, but it uses Nim's unittest module and picks a few critical test cases, so it should be fairly usable by just running that module.

Also Nim's object model prefering value semantics over reference semantics required a small top level API change where rather than a command pattern class, I just have a function.

TinBryn avatar Oct 16 '20 11:10 TinBryn

Thankyou so much for taking the time to translate to Nim!

About the unit test - it is too good I'm afraid. There should be two starting positions. One is a single, failing unit test. The other is a texttest fixture. The fixture is just a main function that prints stuff. I'm not sure what you mean by "it doesn't have support for texttest"? Surely you can print stuff to the console from Nim?

emilybache avatar Oct 19 '20 05:10 emilybache

The failing unit test would be

import unittest
import ../src/items
import ../src/gildedrose

suite "Gilded Rose":

  test "foo":
    var items = @[initItem("foo", 0, 0)]
    items.updateQuality()
    check items[0].name == "fixme"

If that would be enough I will try to modify this PR

codecop avatar Dec 06 '23 11:12 codecop

Thanks, yes please

emilybache avatar Dec 06 '23 14:12 emilybache

Checked out PR, modified the test and merged manually. Thank you.

codecop avatar Dec 07 '23 12:12 codecop