Created
January 8, 2023 02:37
-
-
Save MelbourneDeveloper/41a4b1fca07aea3792011b292596e433 to your computer and use it in GitHub Desktop.
AI Mutation Testing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:test/test.dart'; | |
enum Operation { add, subtract, multiply, divide } | |
int calculate(Operation operation, int a, int b) { | |
switch (operation) { | |
case Operation.add: | |
return a + b; | |
case Operation.subtract: | |
return a - b; | |
case Operation.multiply: | |
return a * b; | |
case Operation.divide: | |
return a ~/ b; | |
} | |
} | |
void main() { | |
test('calculate', () { | |
expect(calculate(Operation.add, 42, 1), 43); | |
}); | |
} | |
test('calculate', () { | |
// Test addition | |
expect(calculate(Operation.add, 1, 1), 2); | |
expect(calculate(Operation.add, -1, 1), 0); | |
expect(calculate(Operation.add, 100, 100), 200); | |
// Test subtraction | |
expect(calculate(Operation.subtract, 1, 1), 0); | |
expect(calculate(Operation.subtract, -1, 1), -2); | |
expect(calculate(Operation.subtract, 100, 100), 0); | |
// Test multiplication | |
expect(calculate(Operation.multiply, 1, 1), 1); | |
expect(calculate(Operation.multiply, -1, 1), -1); | |
expect(calculate(Operation.multiply, 100, 100), 10000); | |
// Test division | |
expect(calculate(Operation.divide, 1, 1), 1); | |
expect(calculate(Operation.divide, -1, 1), -1); | |
expect(calculate(Operation.divide, 100, 100), 1); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment