From 3690af35f916c120d26a3570811e8011a849644e Mon Sep 17 00:00:00 2001 From: Birame Sene Date: Sun, 29 Dec 2024 13:24:57 +0100 Subject: [PATCH] test: set up Deno version test cases --- deno/app/gilded-rose.ts | 38 +++++++++++++++++----------- deno/deno.lock | 19 +++++++++++++- deno/test/gilded-rose_test.ts | 12 +++++++++ deno/test/golden-master-text-test.ts | 4 +-- 4 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 deno/test/gilded-rose_test.ts diff --git a/deno/app/gilded-rose.ts b/deno/app/gilded-rose.ts index db58d678..ef88a83d 100644 --- a/deno/app/gilded-rose.ts +++ b/deno/app/gilded-rose.ts @@ -3,7 +3,7 @@ export class Item { sellIn: number; quality: number; - constructor(name, sellIn, quality) { + constructor(name: string, sellIn: number, quality: number) { this.name = name; this.sellIn = sellIn; this.quality = quality; @@ -19,46 +19,54 @@ export class GildedRose { updateQuality() { for (let i = 0; i < this.items.length; i++) { - if (this.items[i].name != 'Aged Brie' && this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { + if ( + this.items[i].name != "Aged Brie" && + this.items[i].name != "Backstage passes to a TAFKAL80ETC concert" + ) { if (this.items[i].quality > 0) { - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].quality = this.items[i].quality - 1 + if (this.items[i].name != "Sulfuras, Hand of Ragnaros") { + this.items[i].quality = this.items[i].quality - 1; } } } else { if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1 - if (this.items[i].name == 'Backstage passes to a TAFKAL80ETC concert') { + this.items[i].quality = this.items[i].quality + 1; + if ( + this.items[i].name == "Backstage passes to a TAFKAL80ETC concert" + ) { if (this.items[i].sellIn < 11) { if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1 + this.items[i].quality = this.items[i].quality + 1; } } if (this.items[i].sellIn < 6) { if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1 + this.items[i].quality = this.items[i].quality + 1; } } } } } - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { + if (this.items[i].name != "Sulfuras, Hand of Ragnaros") { this.items[i].sellIn = this.items[i].sellIn - 1; } if (this.items[i].sellIn < 0) { - if (this.items[i].name != 'Aged Brie') { - if (this.items[i].name != 'Backstage passes to a TAFKAL80ETC concert') { + if (this.items[i].name != "Aged Brie") { + if ( + this.items[i].name != "Backstage passes to a TAFKAL80ETC concert" + ) { if (this.items[i].quality > 0) { - if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') { - this.items[i].quality = this.items[i].quality - 1 + if (this.items[i].name != "Sulfuras, Hand of Ragnaros") { + this.items[i].quality = this.items[i].quality - 1; } } } else { - this.items[i].quality = this.items[i].quality - this.items[i].quality + this.items[i].quality = this.items[i].quality - + this.items[i].quality; } } else { if (this.items[i].quality < 50) { - this.items[i].quality = this.items[i].quality + 1 + this.items[i].quality = this.items[i].quality + 1; } } } diff --git a/deno/deno.lock b/deno/deno.lock index be56851a..7acb7d55 100644 --- a/deno/deno.lock +++ b/deno/deno.lock @@ -2,7 +2,10 @@ "version": "4", "specifiers": { "jsr:@std/assert@1": "1.0.10", - "jsr:@std/internal@^1.0.5": "1.0.5" + "jsr:@std/assert@^1.0.10": "1.0.10", + "jsr:@std/expect@*": "1.0.10", + "jsr:@std/internal@^1.0.5": "1.0.5", + "jsr:@std/testing@*": "1.0.8" }, "jsr": { "@std/assert@1.0.10": { @@ -11,8 +14,22 @@ "jsr:@std/internal" ] }, + "@std/expect@1.0.10": { + "integrity": "7659b640447887cd1735f866962e10e434f12443b13595b149970c806e6f08db", + "dependencies": [ + "jsr:@std/assert@^1.0.10", + "jsr:@std/internal" + ] + }, "@std/internal@1.0.5": { "integrity": "54a546004f769c1ac9e025abd15a76b6671ddc9687e2313b67376125650dc7ba" + }, + "@std/testing@1.0.8": { + "integrity": "ceef535808fb7568e91b0f8263599bd29b1c5603ffb0377227f00a8ca9fe42a2", + "dependencies": [ + "jsr:@std/assert@^1.0.10", + "jsr:@std/internal" + ] } }, "workspace": { diff --git a/deno/test/gilded-rose_test.ts b/deno/test/gilded-rose_test.ts new file mode 100644 index 00000000..3e6aa4bb --- /dev/null +++ b/deno/test/gilded-rose_test.ts @@ -0,0 +1,12 @@ +import { describe, it } from "jsr:@std/testing/bdd"; +import { expect } from "jsr:@std/expect"; + +import { GildedRose, Item } from "../app/gilded-rose.ts"; + +describe("Gilded Rose specifications", () => { + it("should foo", () => { + const gildedRose = new GildedRose([new Item("foo", 0, 0)]); + const items = gildedRose.updateQuality(); + expect(items[0].name).toBe("fixme"); + }); +}); diff --git a/deno/test/golden-master-text-test.ts b/deno/test/golden-master-text-test.ts index a7d8aabc..95809a31 100644 --- a/deno/test/golden-master-text-test.ts +++ b/deno/test/golden-master-text-test.ts @@ -18,8 +18,8 @@ const items = [ const gildedRose = new GildedRose(items); let days: number = 2; -if (process.argv.length > 2) { - days = +process.argv[2]; +if (Deno.args.length > 0) { + days = +Deno.args[0]; } for (let i = 0; i < days + 1; i++) {