Skip to content

Instantly share code, notes, and snippets.

@MelbourneDeveloper
Created January 8, 2023 02:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MelbourneDeveloper/41a4b1fca07aea3792011b292596e433 to your computer and use it in GitHub Desktop.
Save MelbourneDeveloper/41a4b1fca07aea3792011b292596e433 to your computer and use it in GitHub Desktop.
AI Mutation Testing
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