1
0
mirror of https://github.com/tabler/tabler.git synced 2026-08-08 04:12:26 +04:00
Files
tabler/core/scss/tests/_divide.test.scss
T

46 lines
1.5 KiB
SCSS

// Priority 1 — unit tests for `divide($dividend, $divisor, $precision: 10)`
// from scss/mixins/_functions.scss. This is a hand-rolled long-division
// algorithm (sign handling, configurable precision, unit propagation), so it
// carries the most branching logic of any function in the file.
//
// Note: the divide-by-zero path uses Sass `@error`, which aborts compilation
// and cannot be caught by sass-true (there is no assert-throws), so it is not
// covered here.
@use '../mixins/functions' as *;
@include describe('divide') {
@include it('divides two unitless numbers') {
@include assert-equal(divide(4, 2), 2);
}
@include it('returns a fractional result') {
@include assert-equal(divide(10, 4), 2.5);
@include assert-equal(divide(1, 2), 0.5);
}
@include it('returns 0 when the dividend is 0') {
@include assert-equal(divide(0, 5), 0);
}
@include it('keeps the correct sign for mixed-sign operands') {
@include assert-equal(divide(-6, 2), -3);
@include assert-equal(divide(6, -2), -3);
@include assert-equal(divide(-6, -2), 3);
}
@include it('propagates the dividend unit when the divisor is unitless') {
@include assert-equal(divide(10px, 2), 5px);
@include assert-equal(divide(5%, 2), 2.5%);
}
@include it('cancels matching units to a unitless result') {
@include assert-equal(divide(10px, 2px), 5);
}
@include it('rounds to the requested precision') {
@include assert-equal(divide(2, 3, 0), 1);
@include assert-equal(divide(2, 3, 2), 0.67);
}
}