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

solution #117

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
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
23 changes: 23 additions & 0 deletions .github/workflows/test.yml-template
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Test

on:
pull_request:
branches: [ master ]

jobs:
build:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [20.x]

steps:
- uses: actions/checkout@v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node-version }}
- run: npm install
- run: npm test
153 changes: 150 additions & 3 deletions src/fillTank.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,158 @@
'use strict';

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

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

it(`should return 'undefined'`, () => {
const customer = {
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 8,
},
};

expect(fillTank(customer)).toBeUndefined();
});

it(`should ordered full tank if amount is not given`, () => {
const customer = {
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 10,
},
};

const fuelPrice = 5;

fillTank(customer, fuelPrice);

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

it(`should not pour more than tank can accommodate`, () => {
const customer = {
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 10,
},
};

const fuelPrice = 5;
const fuelAmount = 50;

fillTank(customer, fuelPrice, fuelAmount);

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

// write tests here
it(`should not fill more than client can pay`, () => {
const customer = {
money: 50,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 10,
},
};

const fuelPrice = 5;
const fuelAmount = 20;

fillTank(customer, fuelPrice, fuelAmount);

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

it(`should not pour at all if poured amount is less than 2 liters`, () => {
const customer = {
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 8,
},
};

const fuelPrice = 5;
const fuelAmount = 1;

fillTank(customer, fuelPrice, fuelAmount);

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

it(`should correctly round poured amount, and price`, () => {
const customer = {
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 8,
},
};

const fuelPrice = 5.12;
const fuelAmount = 4.6;

fillTank(customer, fuelPrice, fuelAmount);

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

it(`should done nothing with negative values for price or amount`, () => {
const customer = {
money: 3000,
vehicle: {
maxTankCapacity: 40,
fuelRemains: 8,
},
};

const fuelPrice = -5;
const fuelAmount = -4;

fillTank(customer, fuelPrice, fuelAmount);

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