|
19 | 19 | import { describe, it } from "mocha" |
20 | 20 | import { expect } from "chai" |
21 | 21 |
|
22 | | -// import { Domain, parseDomainSimple } from "../../src/math/domain.mjs" |
23 | | -// |
24 | | -// describe("math.domain", function() { |
25 | | -// describe("#parseDomainSimple", function() { |
26 | | -// it("returns predefined domains", function() { |
27 | | -// const predefinedToCheck = [ |
28 | | -// // Real domains |
29 | | -// { domain: Domain.R, shortcuts: ["R", "ℝ"] }, |
30 | | -// // Zero exclusive real domains |
31 | | -// { domain: Domain.RE, shortcuts: ["RE", "R*", "ℝ*"] }, |
32 | | -// // Real positive domains |
33 | | -// { domain: Domain.RP, shortcuts: ["RP", "R+", "ℝ⁺", "ℝ+"] }, |
34 | | -// // Zero-exclusive real positive domains |
35 | | -// { domain: Domain.RPE, shortcuts: ["RPE", "REP", "R+*", "R*+", "ℝ*⁺", "ℝ⁺*", "ℝ*+", "ℝ+*"] }, |
36 | | -// // Real negative domain |
37 | | -// { domain: Domain.RM, shortcuts: ["RM", "R-", "ℝ⁻", "ℝ-"] }, |
38 | | -// // Zero-exclusive real negative domains |
39 | | -// { domain: Domain.RME, shortcuts: ["RME", "REM", "R-*", "R*-", "ℝ⁻*", "ℝ*⁻", "ℝ-*", "ℝ*-"] }, |
40 | | -// // Natural integers domain |
41 | | -// { domain: Domain.N, shortcuts: ["ℕ", "N", "ZP", "Z+", "ℤ⁺", "ℤ+"] }, |
42 | | -// // Zero-exclusive natural integers domain |
43 | | -// { domain: Domain.NE, shortcuts: ["NE", "NP", "N*", "N+", "ℕ*", "ℕ⁺", "ℕ+", "ZPE", "ZEP", "Z+*", "Z*+", "ℤ⁺*", "ℤ*⁺", "ℤ+*", "ℤ*+"] }, |
44 | | -// // Logarithmic natural domains |
45 | | -// { domain: Domain.NLog, shortcuts: ["NLOG", "ℕˡᵒᵍ", "ℕLOG"] }, |
46 | | -// // All integers domains |
47 | | -// { domain: Domain.Z, shortcuts: ["Z", "ℤ"] }, |
48 | | -// // Zero-exclusive all integers domain |
49 | | -// { domain: Domain.ZE, shortcuts: ["ZE", "Z*", "ℤ*"] }, |
50 | | -// // Negative integers domain |
51 | | -// { domain: Domain.ZM, shortcuts: ["ZM", "Z-", "ℤ⁻", "ℤ-"] }, |
52 | | -// // Zero-exclusive negative integers domain |
53 | | -// { domain: Domain.ZME, shortcuts: ["ZME", "ZEM", "Z-*", "Z*-", "ℤ⁻*", "ℤ*⁻", "ℤ-*", "ℤ*-"] }, |
54 | | -// ] |
55 | | -// |
56 | | -// // Real domains |
57 | | -// for(const { domain, shortcuts } of predefinedToCheck) |
58 | | -// for(const shortcut of shortcuts) |
59 | | -// expect(parseDomainSimple(shortcut)).to.be.equal(domain) |
60 | | -// }) |
61 | | -// |
62 | | -// it("") |
63 | | -// }) |
64 | | -// }) |
| 22 | +import { Domain, EmptySet, parseDomainSimple } from "../../src/math/domain.mjs" |
| 23 | + |
| 24 | +describe("math.domain", function() { |
| 25 | + describe("#parseDomainSimple", function() { |
| 26 | + it("returns empty sets when a domain cannot be parsed", function() { |
| 27 | + expect(parseDomainSimple("∅")).to.be.an.instanceof(EmptySet) |
| 28 | + expect(parseDomainSimple("O")).to.be.an.instanceof(EmptySet) |
| 29 | + expect(parseDomainSimple("AAAAAAAAA")).to.be.an.instanceof(EmptySet) |
| 30 | + expect(parseDomainSimple("???")).to.be.an.instanceof(EmptySet) |
| 31 | + expect(parseDomainSimple("∅").latexMarkup).to.equal("\\emptyset") |
| 32 | + expect(parseDomainSimple("???").toString()).to.equal("∅") |
| 33 | + expect(parseDomainSimple("∅").includes(0)).to.be.false |
| 34 | + expect(parseDomainSimple("∅").includes(Infinity)).to.be.false |
| 35 | + expect(parseDomainSimple("∅").includes(-3)).to.be.false |
| 36 | + |
| 37 | + }) |
| 38 | + |
| 39 | + it("returns predefined domains", function() { |
| 40 | + const predefinedToCheck = [ |
| 41 | + // Real domains |
| 42 | + { domain: Domain.R, shortcuts: ["R", "ℝ"] }, |
| 43 | + // Zero exclusive real domains |
| 44 | + { domain: Domain.RE, shortcuts: ["RE", "R*", "ℝ*"] }, |
| 45 | + // Real positive domains |
| 46 | + { domain: Domain.RP, shortcuts: ["RP", "R+", "ℝ⁺", "ℝ+"] }, |
| 47 | + // Zero-exclusive real positive domains |
| 48 | + { domain: Domain.RPE, shortcuts: ["RPE", "REP", "R+*", "R*+", "ℝ*⁺", "ℝ⁺*", "ℝ*+", "ℝ+*"] }, |
| 49 | + // Real negative domain |
| 50 | + { domain: Domain.RM, shortcuts: ["RM", "R-", "ℝ⁻", "ℝ-"] }, |
| 51 | + // Zero-exclusive real negative domains |
| 52 | + { domain: Domain.RME, shortcuts: ["RME", "REM", "R-*", "R*-", "ℝ⁻*", "ℝ*⁻", "ℝ-*", "ℝ*-"] }, |
| 53 | + // Natural integers domain |
| 54 | + { domain: Domain.N, shortcuts: ["ℕ", "N", "ZP", "Z+", "ℤ⁺", "ℤ+"] }, |
| 55 | + // Zero-exclusive natural integers domain |
| 56 | + { domain: Domain.NE, shortcuts: ["NE", "NP", "N*", "N+", "ℕ*", "ℕ⁺", "ℕ+", "ZPE", "ZEP", "Z+*", "Z*+", "ℤ⁺*", "ℤ*⁺", "ℤ+*", "ℤ*+"] }, |
| 57 | + // Logarithmic natural domains |
| 58 | + { domain: Domain.NLog, shortcuts: ["NLOG", "ℕˡᵒᵍ", "ℕLOG"] }, |
| 59 | + // All integers domains |
| 60 | + { domain: Domain.Z, shortcuts: ["Z", "ℤ"] }, |
| 61 | + // Zero-exclusive all integers domain |
| 62 | + { domain: Domain.ZE, shortcuts: ["ZE", "Z*", "ℤ*"] }, |
| 63 | + // Negative integers domain |
| 64 | + { domain: Domain.ZM, shortcuts: ["ZM", "Z-", "ℤ⁻", "ℤ-"] }, |
| 65 | + // Zero-exclusive negative integers domain |
| 66 | + { domain: Domain.ZME, shortcuts: ["ZME", "ZEM", "Z-*", "Z*-", "ℤ⁻*", "ℤ*⁻", "ℤ-*", "ℤ*-"] }, |
| 67 | + ] |
| 68 | + |
| 69 | + // Real domains |
| 70 | + for(const { domain, shortcuts } of predefinedToCheck) |
| 71 | + for(const shortcut of shortcuts) |
| 72 | + expect(parseDomainSimple(shortcut)).to.be.equal(domain) |
| 73 | + }) |
| 74 | + |
| 75 | + it("returns parsed ranges", function() { |
| 76 | + const parsedClosed = parseDomainSimple("[1;3]") |
| 77 | + expect(parsedClosed.includes(1)).to.be.true |
| 78 | + expect(parsedClosed.includes(2.4)).to.be.true |
| 79 | + expect(parsedClosed.includes(3)).to.be.true |
| 80 | + expect(parsedClosed.includes(3.01)).to.be.false |
| 81 | + expect(parsedClosed.includes(0.99)).to.be.false |
| 82 | + const parsedOpen = parseDomainSimple("]1;3[") |
| 83 | + expect(parsedOpen.includes(1)).to.be.false |
| 84 | + expect(parsedOpen.includes(3)).to.be.false |
| 85 | + expect(parsedOpen.includes(2.4)).to.be.true |
| 86 | + expect(parsedOpen.includes(1.01)).to.be.true |
| 87 | + expect(parsedOpen.includes(2.99)).to.be.true |
| 88 | + const parsedOpenBefore = parseDomainSimple("]1;3]") |
| 89 | + expect(parsedOpenBefore.includes(1)).to.be.false |
| 90 | + expect(parsedOpenBefore.includes(3)).to.be.true |
| 91 | + expect(parsedOpenBefore.includes(2.4)).to.be.true |
| 92 | + expect(parsedOpenBefore.includes(1.01)).to.be.true |
| 93 | + expect(parsedOpenBefore.includes(3.01)).to.be.false |
| 94 | + const parsedOpenAfter = parseDomainSimple("[1;3[") |
| 95 | + expect(parsedOpenAfter.includes(1)).to.be.true |
| 96 | + expect(parsedOpenAfter.includes(3)).to.be.false |
| 97 | + expect(parsedOpenAfter.includes(2.4)).to.be.true |
| 98 | + expect(parsedOpenAfter.includes(0.99)).to.be.false |
| 99 | + expect(parsedOpenAfter.includes(2.99)).to.be.true |
| 100 | + }) |
| 101 | + |
| 102 | + it("does not parse invalid ranges", function() { |
| 103 | + expect(() => parseDomainSimple("]1;2;3[")).to.throw |
| 104 | + expect(() => parseDomainSimple("]1,2;3[")).to.throw |
| 105 | + expect(() => parseDomainSimple("](12);3[")).to.throw |
| 106 | + }) |
| 107 | + }) |
| 108 | +}) |
0 commit comments