Skip to content

Commit

Permalink
Move most bigint unit tests in to their own file.
Browse files Browse the repository at this point in the history
  • Loading branch information
pekim committed Dec 29, 2011
1 parent 753278c commit b8b3422
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 32 deletions.
36 changes: 36 additions & 0 deletions test/unit/token/bigint-test.coffee
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
convertLEBytesToString = require('../../../lib/token/bigint').convertLEBytesToString

module.exports.zero = (test) ->
test.strictEqual('0', convertLEBytesToString(new Buffer([0, 0, 0, 0, 0, 0, 0, 0])))

test.done()

module.exports.smallPositive = (test) ->
test.strictEqual('1', convertLEBytesToString(new Buffer([1, 0, 0, 0, 0, 0, 0, 0])))
test.strictEqual('2', convertLEBytesToString(new Buffer([2, 0, 0, 0, 0, 0, 0, 0])))

test.done()

module.exports.smallNegative = (test) ->
test.strictEqual('-1', convertLEBytesToString(new Buffer([255, 255, 255, 255, 255, 255, 255, 255])))
test.strictEqual('-2', convertLEBytesToString(new Buffer([254, 255, 255, 255, 255, 255, 255, 255])))

test.done()

module.exports.bigPositive = (test) ->
test.strictEqual('9223372036854775807', convertLEBytesToString(new Buffer([255, 255, 255, 255, 255, 255, 255, 127])))

test.done()

module.exports.bigNegative = (test) ->
test.strictEqual('-9223372036854775808', convertLEBytesToString(new Buffer([0, 0, 0, 0, 0, 0, 0, 128])))

test.done()

module.exports.powersOf10 = (test) ->
test.strictEqual('10', convertLEBytesToString(new Buffer([10, 0, 0, 0, 0, 0, 0, 0])))
test.strictEqual('100', convertLEBytesToString(new Buffer([100, 0, 0, 0, 0, 0, 0, 0])))
test.strictEqual('1000', convertLEBytesToString(new Buffer([232, 3, 0, 0, 0, 0, 0, 0])))
test.strictEqual('10000', convertLEBytesToString(new Buffer([16, 39, 0, 0, 0, 0, 0, 0])))

test.done()
37 changes: 5 additions & 32 deletions test/unit/token/row-token-parser-test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,47 +10,20 @@ writeBytes = (buffer, array) ->

module.exports.bigint = (test) ->
colMetaData = [{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt},
{type: dataTypeByName.BigInt}]

buffer = new WritableBuffer(0)

buffer.writeUInt8(TYPE.ROW)
writeBytes( buffer, [0,0,0,0,0,0,0,0,
1,0,0,0,0,0,0,0,
255,255,255,255,255,255,255,255,
2,0,0,0,0,0,0,0,
254,255,255,255,255,255,255,255,
255,255,255,255,255,255,255,127,
0,0,0,0,0,0,0,128,
10,0,0,0,0,0,0,0,
100,0,0,0,0,0,0,0,
232,3,0,0,0,0,0,0,
16,39,0,0,0,0,0,0] )
writeBytes( buffer, [1,0,0,0,0,0,0,0,
255,255,255,255,255,255,255,127] )
buffer = buffer.data

token = parser(buffer, 1, colMetaData)
test.strictEqual(token.length, buffer.length - 1)
test.strictEqual(token.columns.length, 11)
test.strictEqual("0", token.columns[0].value)
test.strictEqual("1", token.columns[1].value)
test.strictEqual("-1", token.columns[2].value)
test.strictEqual("2", token.columns[3].value)
test.strictEqual("-2", token.columns[4].value)
test.strictEqual("9223372036854775807", token.columns[5].value)
test.strictEqual("-9223372036854775808", token.columns[6].value)
test.strictEqual("10", token.columns[7].value)
test.strictEqual("100", token.columns[8].value)
test.strictEqual("1000", token.columns[9].value)
test.strictEqual("10000", token.columns[10].value)
test.strictEqual(token.columns.length, 2)
test.strictEqual("1", token.columns[0].value)
test.strictEqual("9223372036854775807", token.columns[1].value)

test.done()

Expand Down

0 comments on commit b8b3422

Please sign in to comment.