Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 32 additions & 1 deletion enhancing/enhancer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,47 @@ module.exports = {
repair,
get,
};
/*
- Items have `name`, `durability` and `enhancement`.
- The item's `enhancement` it's a number from 0 to 20.
- The item's `durability` it's a number from 0 to 100.*/

function success(item) {

//console.log(item.enhancement)
if (item.enhancement < 20) {
item.enhancement = item.enhancement + 1;
}
else {
throw new Error("Enhancement value greater than 20")
}

return { ...item };
}

/*
- If the item's enhancement is less than 15, the durability of the item is decreased by 5.
- If the item's enhancement is 15 or more, the durability of the item is decreased by 10.
- If the item's enhancement level is greater than 16, the enhancement level decreases by 1 (17 goes down to 16, 18 goes down to 17).*/
function fail(item) {
if (item.enhancement < 15) {
item.durability = item.durability - 5;
}
else if (item.enhancement > 16) {

item.enhancement = item.enhancement - 1
}
else if (item.enhancement = 15) {
item.durability = item.durability - 10
console.log(item.durability, "hi")
}
return { ...item };
}

// a `repair(item)` method that accepts an `item` object and **returns a new item** with the durability restored to 100.
//This method is the simplest of the three and would be a **good starting point** on this project.
function repair(item) {
item.durability = 100;
// console.log(item.durability)
return { ...item };
}

Expand Down
23 changes: 23 additions & 0 deletions enhancing/enhancer.spec.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,25 @@
const { success } = require('./enhancer.js');
const enhancer = require('./enhancer.js');
// test away!
describe("testing",()=>{
it ("repair item",()=>{
item={name:"nandhini",durability:60,enhancement:60}
expect(enhancer.repair(item)).toEqual({ name:"nandhini",durability:100,enhancement:60 })
})
// a `success(item)` method that accepts an `item` object and **returns a new item**
//object modified according to the rules defined by the client for enhancement success.

it("sucess item",()=>{
item= {name:"nandhini",durability:60,enhancement:1}
expect(enhancer.success(item)).toEqual({ name:"nandhini",durability:60,enhancement:2 })
})
it("sucess item fail",()=>{
item={name:"nandhini",durability:60,enhancement:20}
expect(()=>enhancer.success(item)).toThrow()
//expect(() => calculator.quotient(1, 0)).toThrow()
})
it("fail",()=>{
item={name:"nandhini",durability:60,enhancement:15}
expect(enhancer.fail(item)).toEqual({ name:"nandhini",durability:50,enhancement:15 })
})
})
Loading