Skip to content

Commit

Permalink
Merge pull request #10 from samuelematias/lesson10
Browse files Browse the repository at this point in the history
Lesson 10
  • Loading branch information
samuelematias committed Dec 2, 2020
2 parents de8319f + dca4660 commit 517b5a8
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 29 deletions.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ Calculator - [Caster.IO](https://caster.io) project to showcase testing techniqu

[Lesson 9: Sharing code between tests with setUp() and tearDown()](https://caster.io/lessons/lesson-9-sharing-code-between-tests-with-setup-and-teardown) 馃憠馃従 [Branch](https://github.com/samuelematias/calculator_app/tree/lesson9)

[Lesson 10: Testing Futures](https://caster.io/lessons/lesson-10-testing-futures) 馃憠馃従 [Branch](https://github.com/samuelematias/calculator_app/tree/lesson10)

## License

```
Expand Down
3 changes: 3 additions & 0 deletions packages/calculator/lib/src/calculator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ class Calculator {
if (b == 0) throw ArgumentError('You cannot divide by zero');
return a / b;
}

Future<double> powerOfTwo(double a) =>
Future.delayed(const Duration(seconds: 1), () => a * a);
}
66 changes: 37 additions & 29 deletions packages/calculator/test/calculator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,47 +8,55 @@ void main() {
calculator = Calculator();
});

group('add', () {
test('the calculator returns 4 when adding 2 and 2', () {
expect(calculator.add(2, 2), 4);
});
group('Calculator', () {
group('add', () {
test('returns 4 when adding 2 and 2', () {
expect(calculator.add(2, 2), 4);
});

test('the calculator returns 40 when adding 20 and 20', () {
expect(calculator.add(20, 20), 40);
test('returns 40 when adding 20 and 20', () {
expect(calculator.add(20, 20), 40);
});
});
});

group('substract', () {
test('the calculator returns 10 when substracting 10 to 20', () {
expect(calculator.substract(20, 10), 10);
});
group('substract', () {
test('returns 10 when substracting 10 to 20', () {
expect(calculator.substract(20, 10), 10);
});

test('the calculator returns -4 when substracting 8 to 4', () {
expect(calculator.substract(4, 8), -4);
test('returns -4 when substracting 8 to 4', () {
expect(calculator.substract(4, 8), -4);
});
});
});

group('multiple', () {
test('the calculator returns 45 when multiplying 5 tby 9', () {
expect(calculator.multiply(5, 9), 45);
});
group('multiple', () {
test('returns 45 when multiplying 5 tby 9', () {
expect(calculator.multiply(5, 9), 45);
});

test('the calculator returns 18 when multiplying 25 tby 9', () {
expect(calculator.multiply(2, 9), 18);
test('returns 18 when multiplying 25 tby 9', () {
expect(calculator.multiply(2, 9), 18);
});
});
});

group('divide', () {
test('the calculator returns 9 when dividing 27 by 3', () {
expect(calculator.divide(27, 3), 9);
});
group('divide', () {
test('returns 9 when dividing 27 by 3', () {
expect(calculator.divide(27, 3), 9);
});

test('returns 1 when dividing 27 by 27', () {
expect(calculator.divide(27, 27), 1);
});

test('the calculator returns 1 when dividing 27 by 27', () {
expect(calculator.divide(27, 27), 1);
test('throws an ArgumentError when dividing by zero', () {
expect(() => calculator.divide(27, 0), throwsArgumentError);
});
});

test('the calculator throws an ArgumentError when dividing by zero', () {
expect(() => calculator.divide(27, 0), throwsArgumentError);
group('powerOfTwo', () {
test('returns 81 when the input is 9', () async {
expect(await calculator.powerOfTwo(9), 81);
});
});
});
}

0 comments on commit 517b5a8

Please sign in to comment.