approval_tests 1.1.3 copy "approval_tests: ^1.1.3" to clipboard
approval_tests: ^1.1.3 copied to clipboard

Approval Tests implementation in Dart. Inspired by ApprovalTests.

example/main.dart

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

void main() {
  group('Fizz Buzz', () {
    test("verify combinations", () {
      Approvals.verifyAll(
        [3, 5, 15],
        options: const Options(
          reporter: DiffReporter(),
        ),
        processor: (items) => fizzBuzz(items).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;
}
20
likes
105
points
193
downloads

Publisher

verified publishershodev.live

Weekly Downloads

Approval Tests implementation in Dart. Inspired by ApprovalTests.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

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

Documentation

API reference

License

Apache-2.0 (license)

Dependencies

diff_match_patch2, talker, test, test_api

More

Packages that depend on approval_tests