Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

createdTests #106

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
158 changes: 155 additions & 3 deletions src/fillTank.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,163 @@
'use strict';

const { fillTank } = require('./fillTank');

describe('fillTank', () => {
// const { fillTank } = require('./fillTank');
let customer;

beforeEach(() => {
customer = {
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 8,
},
};
});

it('should be declared', () => {
expect(fillTank).toBeInstanceOf(Function);
});

it('should not return anything', () => {
const result = fillTank(customer, 10, 20);

expect(result).toBeUndefined();
});

it(`should change the original 'customer' and not create copy`, () => {
const copy = JSON.parse(JSON.stringify(customer));

fillTank(customer);

it('should ', () => {
expect(customer).not.toEqual(copy);
});

it(`should full tank if 'amount' is not given`, () => {
fillTank(customer, 10);

expect(customer)
.toEqual({
money: 2680,
vehicle: {
fuelRemains: 40,
maxTankCapacity: 40,
},
});
});

it(`should full tank if 'amount' > 'tank capacity'`, () => {
fillTank(customer, 10, 48);

expect(customer)
.toEqual({
money: 2680,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 40,
},
});
});

// write tests here
it(`pour not more fuel than client can buy`, () => {
customer.money = 300;
customer.vehicle.fuelRemains = 2;

fillTank(customer, 10, 43);

expect(customer)
.toEqual({
money: 0,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 32,
},
});
});

it(`pour not more fuel than client can buy,`
+ `when 'amount' is not given`, () => {
customer.money = 300;
customer.vehicle.fuelRemains = 2;

fillTank(customer, 10);

expect(customer)
.toEqual({
money: 0,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 32,
},
});
});

it(`decline transaction if client wants to pour less than 2 liters`, () => {
fillTank(customer, 10, 1);

expect(customer)
.toEqual({
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 8,
},
});
});

it(`decline transaction if client cannot afford more than 2 liters`, () => {
customer.money = 10;

fillTank(customer, 10, 20);

expect(customer)
.toEqual({
money: 10,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 8,
},
});
});

it(`decline transaction if the tank can accomodate < 2L of fuel`, () => {
customer.vehicle.fuelRemains = 39;

fillTank(customer, 10, 20);

expect(customer)
.toEqual({
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 39,
},
});
});

it(`round fuel amount down to tenth`, () => {
fillTank(customer, 10, 5.56);

expect(customer)
.toEqual({
money: 2945,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 13.5,
},
});
});

it(`round the price to nearest hundredth`, () => {
fillTank(customer, 8.782, 20);

expect(customer)
.toEqual({
money: 2824.36,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 28,
},
});
});
});
Loading