it("should generate a valid date below maximum", () => { let max = new Date(Date.UTC(1970, 0, 1, 0, 0, 0, 10)); let schema = new JsonSchema({ type: "string", format: "date-time", maximum: max }); for (let i = 0; i < iterations; i++) { let date = schema.sample(); expect(date).to.be.an.instanceOf(Date); expect(date.valueOf()).to.be.at.most(max.valueOf()); } });
expect(() => { expect(now).to.be.at.most(oneSecondBefore, "blah"); }).to.throw( AssertionError, "blah: expected " + nowUTC + " to be at most " + beforeUTC );
it("[XNOR] Network.train()", function() { const network = new Network(2,1); const initial = network.test(data.XNOR); network.train(data.XNOR); const final = network.test(data.XNOR); expect(final.error).to.be.at.most(initial.error); });
it("should generate a valid int64", () => { let schema = new JsonSchema({ type: "integer", format: "int64" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(MIN_SAFE_INTEGER) .and.at.most(MAX_SAFE_INTEGER); } });
it("should generate a valid number above exclusive minimum", () => { let min = MAX_SAFE_INTEGER - 10; let schema = new JsonSchema({ type: "integer", minimum: min, exclusiveMinimum: true }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.above(min) .and.at.most(MAX_SAFE_INTEGER); } });
expect(() => { expect("foo", "blah").to.have.length.of.at.most(2); }).to.throw( AssertionError, "blah: expected 'foo' to have a length at most 2 but got 3" );
it("should generate a valid date within min/max", () => { let min = new Date(2008, 5, 27, 15, 32, 17, 100); let max = new Date(2008, 5, 27, 15, 32, 17, 200); let schema = new JsonSchema({ type: "string", format: "date-time", minimum: min, maximum: max }); for (let i = 0; i < iterations; i++) { let date = schema.sample(); expect(date).to.be.an.instanceOf(Date); expect(date.valueOf()).to.be.at.least(min.valueOf()); expect(date.valueOf()).to.be.at.most(max.valueOf()); } });
it("[AND] Network.train()", function() { const network = new Network(2,1); const initial = network.test(data.AND); network.train(data.AND); const final = network.test(data.AND); expect(final.error).to.be.at.most(initial.error); });
it("[XOR] Network.train()", function() { const network = new Network(2,1); const initial = network.test(data.XOR); network.train(data.XOR); const final = network.test(data.XOR); expect(final.error).to.be.at.most(initial.error); });
expect(() => { expect(now).to.have.length.of.at.most(2, "blah"); }).to.throw( AssertionError, "blah: expected " + nowUTC + " to have property 'length'" );
it("should generate a valid number below maximum", () => { let max = MIN_SAFE_INTEGER + 10; let schema = new JsonSchema({ type: "integer", maximum: max }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(MIN_SAFE_INTEGER) .and.at.most(max); } });
it("should generate a valid byte", () => { let schema = new JsonSchema({ type: "string", format: "byte" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(0) .and.at.most(255); } });
it("should generate a valid int32", () => { let schema = new JsonSchema({ type: "integer", format: "int32" }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(-2147483648) .and.at.most(2147483647); } });
it("should generate a valid number above minimum", () => { let min = MAX_SAFE_INTEGER - 10; let schema = new JsonSchema({ type: "integer", minimum: min }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(min) .and.at.most(MAX_SAFE_INTEGER); } });
it("should generate a valid number within min/max", () => { let schema = new JsonSchema({ type: "integer", minimum: 1, maximum: 10 }); for (let i = 0; i < iterations; i++) { expect(schema.sample()) .to.be.a("number") .and.satisfy(Number.isFinite) .and.satisfy(isWholeNumber) .and.at.least(1) .and.at.most(10); } });