Commit ad3cf480 by 李楚霏

task-6-subclassing 子类修改测试

parent f8d48a44
export class AgedBrie { import { Item } from "./item";
isAgedBrie() {
return 'Aged Brie';
}
isSulfuras() { export class AgedBrie extends Item{
return 'Sulfuras, Hand of Ragnaros'; constructor(sell_in, quality){
super(sell_in, quality);
this.name = 'Aged Brie';
};
} isAgedBrie() {
return 'Aged Brie';
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert';
} }
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ import { AgedBrie } from "./AgedBrie" ...@@ -2,7 +2,7 @@ import { AgedBrie } from "./AgedBrie"
describe('AgedBrieTest', () => { describe('AgedBrieTest', () => {
it('foo', () => { it('foo', () => {
const agedBrie = new AgedBrie(); const agedBrie = new AgedBrie(2, 0);
const string = agedBrie.isAgedBrie(); const string = agedBrie.isAgedBrie();
expect(string).toEqual('Aged Brie'); expect(string).toEqual('Aged Brie');
}) })
......
export class BackstagePass { import { Item } from "./item";
isAgedBrie() {
return 'Aged Brie';
}
isSulfuras() {
return 'Sulfuras, Hand of Ragnaros';
export class BackstagePass extends Item{
constructor(sell_in, quality) {
super(sell_in, quality);
this.name = 'Backstage passes to a TAFKAL80ETC concert';
} }
isBackStage() { isBackStage() {
......
...@@ -2,7 +2,7 @@ import { BackstagePass } from "./BackstagePass"; ...@@ -2,7 +2,7 @@ import { BackstagePass } from "./BackstagePass";
describe('backstagePassTest', () => { describe('backstagePassTest', () => {
it('foo', () => { it('foo', () => {
const agedBrie = new BackstagePass(); const agedBrie = new BackstagePass(15, 20);
const string = agedBrie.isBackStage(); const string = agedBrie.isBackStage();
expect(string).toEqual('Backstage passes to a TAFKAL80ETC concert'); expect(string).toEqual('Backstage passes to a TAFKAL80ETC concert');
}) })
......
export class Sulfuras { import { Item } from "./item";
isAgedBrie() {
return 'Aged Brie'; export class Sulfuras extends Item{
constructor(sell_in, quality) {
super(sell_in, quality);
this.name = 'Sulfuras, Hand of Ragnaros';
} }
isSulfuras() { isSulfuras() {
return 'Sulfuras, Hand of Ragnaros'; return 'Sulfuras, Hand of Ragnaros';
} }
isBackStage() {
return 'Backstage passes to a TAFKAL80ETC concert';
}
} }
\ No newline at end of file
...@@ -2,7 +2,7 @@ import { Sulfuras } from "./Sulfuras"; ...@@ -2,7 +2,7 @@ import { Sulfuras } from "./Sulfuras";
describe('SulfurasTest', () => { describe('SulfurasTest', () => {
it('foo', () => { it('foo', () => {
const agedBrie = new Sulfuras(); const agedBrie = new Sulfuras(-1, 80);
const string = agedBrie.isSulfuras(); const string = agedBrie.isSulfuras();
expect(string).toEqual('Sulfuras, Hand of Ragnaros'); expect(string).toEqual('Sulfuras, Hand of Ragnaros');
}) })
......
...@@ -26,11 +26,11 @@ export class Item { ...@@ -26,11 +26,11 @@ export class Item {
} }
createBackStagePass(sell_in, quality) { createBackStagePass(sell_in, quality) {
new Item('Backstage passes to a TAFKAL80ETC concert', sell_in, quality); new BackStagePass('Backstage passes to a TAFKAL80ETC concert', sell_in, quality);
} }
createSulfuras(sell_in, quality) { createSulfuras(sell_in, quality) {
new Item('Sulfuras, Hand of Ragnaros', sell_in, quality); new Sulfuras(sell_in, quality);
} }
createNormalItem(name, sell_in, quality) { createNormalItem(name, sell_in, quality) {
...@@ -38,7 +38,7 @@ export class Item { ...@@ -38,7 +38,7 @@ export class Item {
} }
createAgedBrie(sell_in, quality) { createAgedBrie(sell_in, quality) {
new Item('Aged Brie', sell_in, quality); new AgedBrie(sell_in, quality);
} }
_updateItem(item) { _updateItem(item) {
......
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