approval_tests 0.2.0-dev copy "approval_tests: ^0.2.0-dev" to clipboard
approval_tests: ^0.2.0-dev copied to clipboard

Approval Tests implementation in Dart. Inspired by ApprovalTests.

example/main.dart

import 'package:approval_tests/approval_dart.dart';
import 'package:test/test.dart';

void main() {
  group('Fizz Buzz', () {
    test("Verify all combinations", () {
      ApprovalTests.verifyAll(
        inputs: [
          [3, 5, 15],
        ],
        options: Options(
          comparator: IDEComparator(
            ide: ComparatorIDE.visualStudioCode,
          ),
        ),
        processor: (items) => items.map((e) => fizzBuzz(e)).toList().toString(),
      );
    });
  });
}

/// Fizz Buzz kata implementation
List<String> fizzBuzz(int n) {
  final List<String> result = [];

  for (int i = 1; i <= n; i++) {
    // If the current number (`i`) is divisible by both 3 and 5 (or equivalently 15),
    // add the string "FizzBuzz" to the `result` list.
    if (i % 15 == 0) {
      result.add("FizzBuzz");

      // Else, if the current number (`i`) is only divisible by 3,
      // add the string "Fizz" to the `result` list.
    } else if (i % 3 == 0) {
      result.add("Fizz");

      // Else, if the current number (`i`) is only divisible by 5,
      // add the string "Buzz" to the `result` list.
    } else if (i % 5 == 0) {
      result.add("Buzz");

      // If the current number (`i`) is neither divisible by 3 nor 5,
      // add the string representation of that number to the `result` list.
    } else {
      result.add(i.toString());
    }
  }

  return result;
}
14
likes
0
pub points
43%
popularity

Publisher

verified publishershodev.live

Approval Tests implementation in Dart. Inspired by ApprovalTests.

Homepage
Repository (GitHub)
View/report issues

Topics

#testing #approval #approvals #tests #approval-tests

License

unknown (LICENSE)

Dependencies

talker, test

More

Packages that depend on approval_tests