HI, i am creating a unit test for simple game in c# , but they my each test are failing -
whenever run test, failed , output shows value set true actual value false
private list<item> _items; public list<item> items { { return _items; } } public inventory() { _items = new list<item>(); }
this add items sword in inventory
public void put(item itm) { // list<item> items = new list<item>(); items.add(itm); }
this returns true if item in inventory
public bool hasitem(string id) { // item itm = null; // put(itm); bool hasitem = false; foreach (item ident in _items) { if (item.equals(ident, id.tolower())) { hasitem = true; } } return hasitem; }
it takes item inventorey doesnn't remove
public item take(string id) { foreach (item itm in items) { if (item.equals(id, id.tolower())) { return itm; } _items.remove(itm); } return null; }
it removes take item inventory , remove it
public item fetch(string id) { foreach (item itm in items) { if (item.equals(id, id.tolower())) { return itm; } } return null; }
this return description item
public list<string> itemlist { { var description = new list<string>(); foreach (item itm in items) { description.add(itm.fulldescription); } return description; } [testfixture()] class inventoryunittest { [test()] public void add() { inventory id = new inventory(); id.put(new item(new string[] { "sword", "spade" }, "a sword", "this sword weapon")); assert.areequal("paras", id.items[2], "adding"); } [test()] public void areyounot() { inventory id = new inventory(); bool testareyounot = id.hasitem("mine"); assert.areequal(false, testareyounot, "no"); } [test()] public void areyou() { inventory id = new inventory(); bool testareyou = id.hasitem("sword"); assert.areequal(true, testareyou, "yes"); } [test()] public void fetchitem() { inventory id = new inventory(); id.put(new item(new string[] { "sword", "spade" }, "a sword", "this sword weapon")); id.fetch("sword"); assert.areequal("sword", id.items[0], "fetching item"); } [test()] public void takeitem() { inventory id = new inventory(); id.put(new item(new string[] { "sword", "spade" }, "a sword", "this sword weapon")); assert.areequal("sword", id.items[1], "fetching item"); } [test()] public void itemlist() { inventory id = new inventory(); id.put(new item(new string[] { "sword", "spade" }, "a sword", "this sword weapon")); assert.areequal("this sword weapon", id.items[0], "description"); }
Comments
Post a Comment