UNPKG

@dpkit/table

Version:

Data Package implementation in TypeScript.

84 lines (74 loc) 2.07 kB
import type { Schema } from "@dpkit/core" import { DataFrame } from "nodejs-polars" import { describe, expect, it } from "vitest" import { inspectTable } from "../../table/index.ts" describe("inspectTable (cell/minimum)", () => { it("should not report errors for valid values", async () => { const table = DataFrame({ price: [10.5, 20.75, 30.0], }).lazy() const schema: Schema = { fields: [ { name: "price", type: "number", constraints: { minimum: 5 }, }, ], } const errors = await inspectTable(table, { schema }) expect(errors).toHaveLength(0) }) it("should report an error for invalid values", async () => { const table = DataFrame({ temperature: [20.5, 30.0, 40, 3.5], }).lazy() const schema: Schema = { fields: [ { name: "temperature", type: "number", constraints: { minimum: 10 }, }, ], } const errors = await inspectTable(table, { schema }) expect(errors.filter(e => e.type === "cell/minimum")).toHaveLength(1) expect(errors).toContainEqual({ type: "cell/minimum", fieldName: "temperature", rowNumber: 4, cell: "3.5", }) }) it("should report an error for invalid values (exclusive)", async () => { const table = DataFrame({ temperature: [20.5, 30.0, 10.0, 5.5], }).lazy() const schema: Schema = { fields: [ { name: "temperature", type: "number", constraints: { exclusiveMinimum: 10 }, }, ], } const errors = await inspectTable(table, { schema }) expect(errors.filter(e => e.type === "cell/exclusiveMinimum")).toHaveLength( 2, ) expect(errors).toContainEqual({ type: "cell/exclusiveMinimum", fieldName: "temperature", rowNumber: 3, cell: "10", }) expect(errors).toContainEqual({ type: "cell/exclusiveMinimum", fieldName: "temperature", rowNumber: 4, cell: "5.5", }) }) })