|
434 | 434 | @test nthroot(Interval{BigFloat}(-81, -16), -4) == ∅
|
435 | 435 | @test nthroot(Interval{BigFloat}(-81, -16), 1) == Interval{BigFloat}(-81, -16)
|
436 | 436 | end
|
| 437 | + |
| 438 | +# approximation used for testing (not to rely on ≈ for intervals) |
| 439 | +# ⪆(x, y) = (x ≈ y) && (x ⊇ y) |
| 440 | +⪆(x::Interval, y::Interval) = x.lo ≈ y.lo && x.hi ≈ y.hi && x ⊇ y |
| 441 | + |
| 442 | +@testset "`mod`" begin |
| 443 | + r = 0.0625 |
| 444 | + x = r..(1+r) |
| 445 | + @test mod(x, 1) == mod(x, 1.0) == 0..1 |
| 446 | + @test mod(x, 2) == mod(x, 2.0) ⪆ x |
| 447 | + @test mod(x, 2.5) ⪆ x |
| 448 | + @test mod(x, 0.5) == 0..0.5 |
| 449 | + @test mod(x, -1) == mod(x, -1.0) == -1..0 |
| 450 | + @test mod(x, -2) == mod(x, -2.0) ⪆ -2+x |
| 451 | + @test mod(x, -2.5) ⪆ -2.5+x |
| 452 | + @test mod(x, -0.5) == -0.5..0 |
| 453 | + |
| 454 | + x = (-1+r) .. -r |
| 455 | + @test mod(x, 1) == mod(x, 1.0) ⪆ 1+x |
| 456 | + @test mod(x, 2) == mod(x, 2.0) ⪆ 2+x |
| 457 | + @test mod(x, 2.5) ⪆ 2.5+x |
| 458 | + @test mod(x, 0.5) == 0..0.5 |
| 459 | + @test mod(x, -1) == mod(x, -1.0) ⪆ x |
| 460 | + @test mod(x, -2) == mod(x, -2.0) ⪆ x |
| 461 | + @test mod(x, -2.5) ⪆ x |
| 462 | + @test mod(x, -0.5) == -0.5..0 |
| 463 | + |
| 464 | + x = -r .. 1-r |
| 465 | + @test mod(x, 1) == mod(x, 1.0) == 0..1 |
| 466 | + @test mod(x, 2) == mod(x, 2.0) == 0..2 |
| 467 | + @test mod(x, 2.5) == 0..2.5 |
| 468 | + @test mod(x, 0.5) == 0..0.5 |
| 469 | + @test mod(x, -1) == mod(x, -1.0) == -1..0 |
| 470 | + @test mod(x, -2) == mod(x, -2.0) == -2..0 |
| 471 | + @test mod(x, -2.5) == -2.5..0 |
| 472 | + @test mod(x, -0.5) == -0.5..0 |
| 473 | + |
| 474 | + # TODO - implement mod for two intervals |
| 475 | + @test_throws ArgumentError mod(1..2, 1.4..1.5) |
| 476 | + @test_throws ArgumentError mod(1.0, 1.4..1.5) |
| 477 | +end |
0 commit comments