Skip to content

Commit

Permalink
Merge pull request #9 from samuelematias/lesson9
Browse files Browse the repository at this point in the history
Lesson 9
  • Loading branch information
samuelematias committed Dec 2, 2020
2 parents 2c5e871 + 0932835 commit de8319f
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 10 deletions.
2 changes: 1 addition & 1 deletion .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ A few sentences describing the PR.

## Preview

If there if, show the preview with screenshot.
If there if, show the preview with screenshot.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ Calculator - [Caster.IO](https://caster.io) project to showcase testing techniqu

[Lesson 8: Testing code that throws an Error or an Exception](https://caster.io/lessons/lesson-8-testing-code-that-throws-an-error-or-an-exception) 👉🏾 [Branch](https://github.com/samuelematias/calculator_app/tree/lesson8)

[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)

## License

```
Expand Down
15 changes: 6 additions & 9 deletions packages/calculator/test/calculator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,55 +2,52 @@ import 'package:calculator/calculator.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
Calculator calculator;

setUp(() {
calculator = Calculator();
});

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

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

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

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

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

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

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

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

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

0 comments on commit de8319f

Please sign in to comment.