Commit 56cb9c8f by 李楚霏

gildedrose --测试

parent 4696c95c
import { GildedRose } from './gilded-rose'
import { Item } from './item'
const items = [
new Item('+5 Dexterity Vest', 10, 20), //
new Item('Aged Brie', 2, 0), //
new Item('Elixir of the Mongoose', 5, 7), //
new Item('Sulfuras, Hand of Ragnaros', 0, 80), //
new Item('Sulfuras, Hand of Ragnaros', -1, 80),
new Item('Backstage passes to a TAFKAL80ETC concert', 15, 20),
new Item('Backstage passes to a TAFKAL80ETC concert', 10, 49),
new Item('Backstage passes to a TAFKAL80ETC concert', 5, 49),
new Item('Backstage passes to a TAFKAL80ETC concert', 1, 20),
// this conjured item does not work properly yet
new Item('Conjured Mana Cake', 3, 6),
]
const app = new GildedRose(items)
const days = 3
const result = []
result.push('OMGHAI')
for (let i = 0; i < days; i++) {
result.push(`-------- day ${i} --------`)
result.push('name, sellIn, quality')
for (const item of items) {
result.push(item.toString())
}
result.push('')
app.update_quality()
}
console.log(result.join('\n'))
export class GildedRose {
items
constructor(items) {
this.items = items
}
update_quality() {
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].quality > 0) {
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'
) {
if (this.items[i].sell_in < 11) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
}
}
if (this.items[i].sell_in < 6) {
if (this.items[i].quality < 50) {
this.items[i].quality = this.items[i].quality + 1
}
}
}
}
}
if (this.items[i].name != 'Sulfuras, Hand of Ragnaros') {
this.items[i].sell_in = this.items[i].sell_in - 1
}
if (this.items[i].sell_in < 0) {
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
}
}
} else {
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
}
}
}
}
}
}
import { GildedRose } from './gilded-rose'
import { Item } from './item'
describe('GildedRoseTest', () => {
it('foo', () => {
const items = [new Item('foo', 1, 5)]
const app = new GildedRose(items)
app.update_quality()
expect(app.items[0].name).toEqual('foo')
expect(app.items[0].quality).toEqual(4)
expect(app.items[0].sell_in).toEqual(0)
})
})
export class Item {
name
sell_in
quality
constructor(name, sell_in, quality) {
this.name = name
this.sell_in = sell_in
this.quality = quality
}
toString() {
return `${this.name}, ${this.sell_in}, ${this.quality}`
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment