Skip to content

Commit

Permalink
Move decimal tests to vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
domoritz committed Apr 18, 2024
1 parent 3702992 commit 28ebb3a
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
13 changes: 4 additions & 9 deletions js/test/unit/bn-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,14 +93,9 @@ describe(`BN`, () => {
expect(n3.valueOf()).toBe(-1);
const n4 = new BN(new Uint32Array([0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF]), true);
expect(n4.valueOf(1)).toBe(-0.1);

const n5 = BN.decimal(new Uint32Array([0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF]));
expect(n5.valueOf()).toBe(-1);
const n6 = BN.decimal(new Uint32Array([0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF]), 1);
expect(n6.valueOf()).toBe(-0.1);
// const n7 = new BN(new Uint32Array([0x00000000, 0x00000000, 0x00000000, 0x80000000]), false);
// expect(n7.valueOf()).toBe(1.7014118346046923e+38);
// const n8 = new BN(new Uint32Array([0x00000000, 0x00000000, 0x00000000, 0x80000000]), false);
// expect(n8.valueOf(1)).toBe(1.7014118346046923e+37);
// const n5 = new BN(new Uint32Array([0x00000000, 0x00000000, 0x00000000, 0x80000000]), false);
// expect(n5.valueOf()).toBe(1.7014118346046923e+38);
// const n6 = new BN(new Uint32Array([0x00000000, 0x00000000, 0x00000000, 0x80000000]), false);
// expect(n6.valueOf(1)).toBe(1.7014118346046923e+37);
});
});
12 changes: 11 additions & 1 deletion js/test/unit/vector/numeric-vector-tests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import {
util,
Vector, makeVector, vectorFromArray, makeData,
Float, Float16, Float32, Float64,
Int, Int8, Int16, Int32, Int64, Uint8, Uint16, Uint32, Uint64, DataType
Int, Int8, Int16, Int32, Int64, Uint8, Uint16, Uint32, Uint64, DataType, Decimal
} from 'apache-arrow';
import type {
TypedArray,
Expand Down Expand Up @@ -233,6 +233,16 @@ describe(`IntVector`, () => {
});
});

describe(`DecimalVector`, () => {
test(`Values get scaled by the scale in the type`, () => {
const vec1 = vectorFromArray([new Uint32Array([0x00000001, 0x00000000, 0x00000000, 0x00000000])], new Decimal(0, 10));
expect(+vec1.get(0)!).toBe(1);

const vec2 = vectorFromArray([new Uint32Array([0x00000001, 0x00000000, 0x00000000, 0x00000000])], new Decimal(1, 10));
expect(+vec2.get(0)!).toBe(0.1);
});
});

function testIntVector<T extends Int>(DataType: new () => T, values?: Array<any>) {

const type = new DataType();
Expand Down

0 comments on commit 28ebb3a

Please sign in to comment.