text: import{columnIndexOf,columnMinValue,columnMaxValue,columnExtents,columnUnique,columnMinDiff}from"./datatable-utils";var schema=[{name:"DateRange",type:"interval"},{name:"Date",type:"date"},{name:"Country"},{name:"Name",type:"string"},{name:"Revenue",type:"number"},{name:"Status",type:"number"}],data=[[{start:+new Date(2018,0,1),end:+new Date(2018,1,1)},+new Date(2018,0,15),"India","Tata",1e4,0],[{start:+new Date(2016,5,1),end:+new Date(2016,7,18)},+new Date(2017,7,2),"India",null,null,0],[null,+new Date(2018,0,1),null,"Google",25e3,0],[{start:+new Date(2017,0,1),end:+new Date(2018,1,15)},undefined,"USA","Facebook",5e4,0],[{start:+new Date(2015,0,1),end:+new Date(2015,1,15)},+new Date(2015,0,19),"USA","Netflix",undefined,0]];describe("columnIndexOf test cases",function(){it("returns the 0 based index",function(){expect(columnIndexOf("Country",schema)).toBe(2)});it("returns -1 for wrong column",function(){expect(columnIndexOf("Countryyaa",schema)).toBe(-1)});it("returns null for missing column name and schema name",function(){expect(columnIndexOf("Countryyaa")).toBeNull();expect(columnIndexOf(null,schema)).toBeNull()})});describe("columnMinValue test cases",function(){it("returns the minimum value from a number column",function(){expect(columnMinValue("Revenue",data,schema)).toBe(1e4)});it("returns the minimum value from a date column",function(){expect(columnMinValue("Date",data,schema)).toBe(+new Date(2015,0,19))});it("returns the minimum start value from an interval column",function(){expect(columnMinValue("DateRange",data,schema)).toBe(+new Date(2015,0,1))});it("returns 0 from an all zero column",function(){expect(columnMinValue("Status",data,schema)).toBe(0)})});describe("columnMaxValue test cases",function(){it("returns the maximum value from a number column",function(){expect(columnMaxValue("Revenue",data,schema)).toBe(5e4)});it("returns the maximum value from a date column",function(){expect(columnMaxValue("Date",data,schema)).toBe(+new Date(2018,0,15))});it("returns the maximum end value from an interval column",function(){expect(columnMaxValue("DateRange",data,schema)).toBe(+new Date(2018,1,15))});it("returns 0 from an all zero column",function(){expect(columnMaxValue("Status",data,schema)).toBe(0)})});describe("columnExtents test cases",function(){it("returns the maximum value from a number column",function(){expect(columnExtents("Revenue",data,schema)).toEqual({min:1e4,max:5e4})});it("returns the maximum value from a date column",function(){expect(columnExtents("Date",data,schema)).toEqual({min:+new Date(2015,0,19),max:+new Date(2018,0,15)})});it("returns the maximum end value from an interval column",function(){expect(columnExtents("DateRange",data,schema)).toEqual({min:+new Date(2015,0,1),max:+new Date(2018,1,15)})});it("returns 0 from an all zero column",function(){expect(columnExtents("Status",data,schema)).toEqual({min:0,max:0})})});describe("columnUnique test cases",function(){it("returns the maximum value from a number column",function(){expect(columnUnique("Revenue",data,schema)).toEqual([1e4,null,25e3,5e4,undefined])});it("returns the maximum value from a string column",function(){expect(columnUnique("Country",data,schema)).toEqual(["India",null,"USA"])})});describe("columnMinDiff test cases",function(){it("when all values are null returns null",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",null],["B",null],["C",null]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(null)});it("when all values are undefined returns null",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",undefined],["B",undefined],["C",undefined]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(null)});it("when all values are 0 returns 0",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",0],["B",0],["C",0]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(0)});it("when all values are same returns 0",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",10],["B",10],["C",10]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(0)});it("returns difference between numbers when negative values are present",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",-10],["B",8],["C",-3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(7);dataCMD=[["A",-10],["B",8],["C",-3],["C",-10]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(0)});it("returns difference between numbers when separated by null",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",8],["B",null],["C",null],["D",3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(5)});it("returns difference between numbers when separated by undefined",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",8],["B",undefined],["C",undefined],["D",3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(5)});it("returns difference between numbers when separated by null and undefined",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",8],["B",null],["C",undefined],["D",3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(5)});it("returns difference between numbers when 0 present",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",8],["B",12],["C",0],["D",3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(3)});it("returns difference between numbers when 0 and null present",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",8],["B",null],["C",0],["D",3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(3)});it("returns difference between numbers when 0 and undefined present",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",8],["B",undefined],["C",0],["D",3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(3)});it("returns difference between numbers when 0, undefined and null present",function(){var schemaCMD=[{name:"Item",type:"string"},{name:"Value",type:"number"}],dataCMD=[["A",8],["B",null],["C",0],["D",undefined],["E",undefined],["F",3]];expect(columnMinDiff("Value",dataCMD,schemaCMD,"Item")).toBe(3)})});