faissaloux/pest-plugin-math

Math plugin for Pest PHP

v1.4.0 2024-10-18 18:23 UTC

This package is auto-updated.

Last update: 2024-12-19 15:43:36 UTC


README

This plugin affords math related expectations.

Tests Codecov Packagist Version Packagist License

toBeDivisibleBy()

    expect(8)->toBeDivisibleBy(4);
    expect(8)->not->toBeDivisibleBy(3);

toBePowerOf()

    expect(4096)->toBePowerOf(8);
    expect(128)->not->toBePowerOf(3);

toBeMaxOf()

    expect(6)->toBeMaxOf([-6, 0, 6]);
    expect(5.5)->not->toBeMaxOf([2, 4.2, 5.5, 6]);

toBeMinOf()

    expect(-6)->toBeMinOf([-6, 0, 1]);
    expect(5.5)->not->toBeMinOf([2, 4.2, 5.5, 6]);

toBeEven()

    expect(6)->toBeEven();
    expect(7)->not->toBeEven();

toBeOdd()

    expect(7)->toBeOdd();
    expect(6)->not->toBeOdd();

toBePrime()

    expect(3)->toBePrime();
    expect(6)->not->toBePrime();

toBePositive()

    expect(1)->toBePositive();
    expect(-2)->not->toBePositive();

toBeNegative()

    expect(-1)->toBeNegative();
    expect(2)->not->toBeNegative();

toBeSqrtOf()

    expect(3)->toBeSqrtOf(9);
    expect(3.16)->toBeSqrtOf(10, 2);
    expect(2)->not->toBeSqrtOf(9);

toBeFactorialOf()

    expect(6)->toBeFactorialOf(3);
    expect(4)->not->toBeFactorialOf(2);

toBeAbsoluteOf()

    expect(3)->toBeAbsoluteOf(-3);
    expect(-3)->not->toBeAbsoluteOf(-3);

toBeLogarithmOf()


Base default is euler's number.

    expect(0.69897000433602)->toBeLogarithmOf(number: 5, base: 10);
    expect(1)->not->toBeLogarithmOf(number: 1);

toBeSumOf()

    expect(6)->toBeSumOf([1, 2, 3]);
    expect(4)->not->toBeSumOf([2, 3]);

toBeSummationOf()

    expect(2)->toBeSummationOf(fn (int $x) => $x * 2, from: 0, to: 1);
    expect(3)->not->toBeSummationOf(fn (int $x) => $x * 2, from: 0, to: 1);