mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
finishes porting
This commit is contained in:
parent
d6e0786611
commit
8e8ec5624c
@ -6,7 +6,7 @@
|
|||||||
"subdirs" : true
|
"subdirs" : true
|
||||||
},
|
},
|
||||||
"package-specs": {
|
"package-specs": {
|
||||||
"module": "es6",
|
"module": "commonjs",
|
||||||
"in-source": true
|
"in-source": true
|
||||||
},
|
},
|
||||||
"suffix": ".bs.js",
|
"suffix": ".bs.js",
|
||||||
|
|||||||
@ -1,9 +0,0 @@
|
|||||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
||||||
|
|
||||||
|
|
||||||
console.log("Hello, ReScript");
|
|
||||||
|
|
||||||
export {
|
|
||||||
|
|
||||||
}
|
|
||||||
/* Not a pure module */
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
|
|
||||||
Js.log("Hello, ReScript")
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
// Generated by ReScript, PLEASE EDIT WITH CARE
|
|
||||||
|
|
||||||
import * as Jest from "@glennsl/rescript-jest/src/jest.bs.js";
|
|
||||||
|
|
||||||
Jest.test("hey", (function (param) {
|
|
||||||
return Jest.Expect.toBe(Jest.Expect.expect(1), 1);
|
|
||||||
}));
|
|
||||||
|
|
||||||
export {
|
|
||||||
|
|
||||||
}
|
|
||||||
/* Not a pure module */
|
|
||||||
@ -1,6 +0,0 @@
|
|||||||
open Jest
|
|
||||||
open Expect
|
|
||||||
|
|
||||||
test("hey", () => {
|
|
||||||
1->expect->toBe(1)
|
|
||||||
})
|
|
||||||
94
rescript/src/GildedRose.bs.js
Normal file
94
rescript/src/GildedRose.bs.js
Normal file
@ -0,0 +1,94 @@
|
|||||||
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
|
||||||
|
function make(name, sellIn, quality) {
|
||||||
|
return {
|
||||||
|
name: name,
|
||||||
|
sellIn: sellIn,
|
||||||
|
quality: quality
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
var Item = {
|
||||||
|
make: make
|
||||||
|
};
|
||||||
|
|
||||||
|
function updateQuality(items) {
|
||||||
|
return items.map(function (item) {
|
||||||
|
var newItem = item;
|
||||||
|
if (item.name !== "Aged Brie" && item.name !== "Backstage passes to a TAFKAL80ETC concert") {
|
||||||
|
if (item.quality > 0 && item.name !== "Sulfuras, Hand of Ragnaros") {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn,
|
||||||
|
quality: item.quality - 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if (item.quality < 50) {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn,
|
||||||
|
quality: item.quality + 1 | 0
|
||||||
|
};
|
||||||
|
if (item.name === "Backstage passes to a TAFKAL80ETC concert") {
|
||||||
|
if (item.sellIn < 11 && item.quality < 50) {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn,
|
||||||
|
quality: item.quality + 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (item.sellIn < 6 && item.quality < 50) {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn,
|
||||||
|
quality: item.quality + 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (item.name !== "Sulfuras, Hand of Ragnaros") {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn - 1 | 0,
|
||||||
|
quality: item.quality
|
||||||
|
};
|
||||||
|
}
|
||||||
|
if (item.sellIn < 0) {
|
||||||
|
if (item.name !== "Aged Brie") {
|
||||||
|
if (item.name !== "Backstage passes to a TAFKAL80ETC concert") {
|
||||||
|
if (item.quality > 0 && item.name !== "Sulfuras, Hand of Ragnaros") {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn,
|
||||||
|
quality: item.quality - 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
} else {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn,
|
||||||
|
quality: 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
} else if (item.quality < 50) {
|
||||||
|
newItem = {
|
||||||
|
name: item.name,
|
||||||
|
sellIn: item.sellIn,
|
||||||
|
quality: item.quality + 1 | 0
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
return newItem;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.Item = Item;
|
||||||
|
exports.updateQuality = updateQuality;
|
||||||
|
/* No side effect */
|
||||||
65
rescript/src/GildedRose.res
Normal file
65
rescript/src/GildedRose.res
Normal file
@ -0,0 +1,65 @@
|
|||||||
|
module Item = {
|
||||||
|
type t = {
|
||||||
|
name: string,
|
||||||
|
sellIn: int,
|
||||||
|
quality: int,
|
||||||
|
}
|
||||||
|
|
||||||
|
let make = (~name, ~sellIn, ~quality): t => {
|
||||||
|
name,
|
||||||
|
sellIn,
|
||||||
|
quality,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let updateQuality = (items: array<Item.t>) => {
|
||||||
|
items->Js.Array2.map(item => {
|
||||||
|
let newItem = ref(item)
|
||||||
|
|
||||||
|
if item.name != "Aged Brie" && item.name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if item.quality > 0 {
|
||||||
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
newItem := {...item, quality: item.quality - 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if item.quality < 50 {
|
||||||
|
newItem := {...item, quality: item.quality + 1}
|
||||||
|
|
||||||
|
if item.name == "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if item.sellIn < 11 {
|
||||||
|
if item.quality < 50 {
|
||||||
|
newItem := {...item, quality: item.quality + 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.sellIn < 6 {
|
||||||
|
if item.quality < 50 {
|
||||||
|
newItem := {...item, quality: item.quality + 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
newItem := {...item, sellIn: item.sellIn - 1}
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.sellIn < 0 {
|
||||||
|
if item.name != "Aged Brie" {
|
||||||
|
if item.name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
if item.quality > 0 {
|
||||||
|
if item.name != "Sulfuras, Hand of Ragnaros" {
|
||||||
|
newItem := {...item, quality: item.quality - 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
newItem := {...item, quality: 0}
|
||||||
|
}
|
||||||
|
} else if item.quality < 50 {
|
||||||
|
newItem := {...item, quality: item.quality + 1}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newItem.contents
|
||||||
|
})
|
||||||
|
}
|
||||||
20
rescript/src/GildedRose_test.bs.js
Normal file
20
rescript/src/GildedRose_test.bs.js
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Jest = require("@glennsl/rescript-jest/src/jest.bs.js");
|
||||||
|
var Caml_array = require("rescript/lib/js/caml_array.js");
|
||||||
|
var GildedRose = require("./GildedRose.bs.js");
|
||||||
|
|
||||||
|
Jest.describe("Gilded Rose", (function (param) {
|
||||||
|
Jest.test("should foo", (function (param) {
|
||||||
|
var items = [{
|
||||||
|
name: "foo",
|
||||||
|
sellIn: 0,
|
||||||
|
quality: 0
|
||||||
|
}];
|
||||||
|
var updatedItems = GildedRose.updateQuality(items);
|
||||||
|
return Jest.Expect.toBe(Jest.Expect.expect(Caml_array.get(updatedItems, 0).name), "fixme");
|
||||||
|
}));
|
||||||
|
}));
|
||||||
|
|
||||||
|
/* Not a pure module */
|
||||||
11
rescript/src/GildedRose_test.res
Normal file
11
rescript/src/GildedRose_test.res
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
open Jest
|
||||||
|
open Expect
|
||||||
|
open GildedRose
|
||||||
|
|
||||||
|
describe("Gilded Rose", () => {
|
||||||
|
test("should foo", () => {
|
||||||
|
let items: array<Item.t> = [{name: "foo", sellIn: 0, quality: 0}]
|
||||||
|
let updatedItems = updateQuality(items)
|
||||||
|
expect(updatedItems[0].name)->toBe("fixme")
|
||||||
|
})
|
||||||
|
})
|
||||||
42
rescript/src/TextTest.bs.js
Normal file
42
rescript/src/TextTest.bs.js
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// Generated by ReScript, PLEASE EDIT WITH CARE
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
var Process = require("process");
|
||||||
|
var Belt_Array = require("rescript/lib/js/belt_Array.js");
|
||||||
|
var Caml_array = require("rescript/lib/js/caml_array.js");
|
||||||
|
var GildedRose = require("./GildedRose.bs.js");
|
||||||
|
var Belt_Option = require("rescript/lib/js/belt_Option.js");
|
||||||
|
var Caml_format = require("rescript/lib/js/caml_format.js");
|
||||||
|
|
||||||
|
console.log("OMGHAI!");
|
||||||
|
|
||||||
|
var items = {
|
||||||
|
contents: [
|
||||||
|
GildedRose.Item.make("+5 Dexterity Vest", 10, 20),
|
||||||
|
GildedRose.Item.make("Aged Brie", 2, 0),
|
||||||
|
GildedRose.Item.make("Elixir of the Mongoose", 5, 7),
|
||||||
|
GildedRose.Item.make("Sulfuras, Hand of Ragnaros", 0, 80),
|
||||||
|
GildedRose.Item.make("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||||
|
GildedRose.Item.make("Backstage passes to a TAFKAL80ETC concert", 15, 20),
|
||||||
|
GildedRose.Item.make("Backstage passes to a TAFKAL80ETC concert", 10, 49),
|
||||||
|
GildedRose.Item.make("Backstage passes to a TAFKAL80ETC concert", 5, 49),
|
||||||
|
GildedRose.Item.make("Conjured Mana Cake", 3, 6)
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
|
var days = Belt_Option.mapWithDefault(Belt_Array.get(Process.argv, 2), 31, Caml_format.int_of_string);
|
||||||
|
|
||||||
|
for(var i = 0; i <= days; ++i){
|
||||||
|
console.log("-------- day " + String(i) + " --------");
|
||||||
|
console.log("name, sellIn, quality");
|
||||||
|
for(var j = 0 ,j_finish = items.contents.length; j < j_finish; ++j){
|
||||||
|
var item = Caml_array.get(items.contents, j);
|
||||||
|
console.log(item.name + ", " + String(item.sellIn) + ", " + String(item.quality));
|
||||||
|
}
|
||||||
|
console.log("");
|
||||||
|
items.contents = GildedRose.updateQuality(items.contents);
|
||||||
|
}
|
||||||
|
|
||||||
|
exports.items = items;
|
||||||
|
exports.days = days;
|
||||||
|
/* Not a pure module */
|
||||||
28
rescript/src/TextTest.res
Normal file
28
rescript/src/TextTest.res
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
open GildedRose
|
||||||
|
|
||||||
|
Js.log("OMGHAI!")
|
||||||
|
|
||||||
|
let items: ref<array<Item.t>> = ref([
|
||||||
|
Item.make(~name="+5 Dexterity Vest", ~sellIn=10, ~quality=20),
|
||||||
|
Item.make(~name="Aged Brie", ~sellIn=2, ~quality=0),
|
||||||
|
Item.make(~name="Elixir of the Mongoose", ~sellIn=5, ~quality=7),
|
||||||
|
Item.make(~name="Sulfuras, Hand of Ragnaros", ~sellIn=0, ~quality=80),
|
||||||
|
Item.make(~name="Sulfuras, Hand of Ragnaros", ~sellIn=-1, ~quality=80),
|
||||||
|
Item.make(~name="Backstage passes to a TAFKAL80ETC concert", ~sellIn=15, ~quality=20),
|
||||||
|
Item.make(~name="Backstage passes to a TAFKAL80ETC concert", ~sellIn=10, ~quality=49),
|
||||||
|
Item.make(~name="Backstage passes to a TAFKAL80ETC concert", ~sellIn=5, ~quality=49),
|
||||||
|
Item.make(~name="Conjured Mana Cake", ~sellIn=3, ~quality=6),
|
||||||
|
])
|
||||||
|
|
||||||
|
let days = Node.Process.argv->Belt.Array.get(2)->Belt.Option.mapWithDefault(31, int_of_string)
|
||||||
|
|
||||||
|
for i in 0 to days {
|
||||||
|
Js.log("-------- day " ++ string_of_int(i) ++ " --------")
|
||||||
|
Js.log("name, sellIn, quality")
|
||||||
|
for j in 0 to Js.Array2.length(items.contents) - 1 {
|
||||||
|
let item = items.contents[j]
|
||||||
|
Js.log(item.name ++ ", " ++ string_of_int(item.sellIn) ++ ", " ++ string_of_int(item.quality))
|
||||||
|
}
|
||||||
|
Js.log("")
|
||||||
|
items := updateQuality(items.contents)
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user