Skip to content

Commit

Permalink
test: Check if 0, "0" or "0.0" is handled correctly and it is
Browse files Browse the repository at this point in the history
  • Loading branch information
ztalbot2000 committed Feb 11, 2021
1 parent 3369447 commit 019c6d2
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 1 deletion.
41 changes: 41 additions & 0 deletions test/characteristicValueToItsProperType.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,47 @@ describe('Test characteristicValueToItsProperType.', ( ) =>
assert.equal( result, expectedResult, "configHasCharacteristicProps of valid data with full properties returned incorrect result: " + result );
});

it('characteristicValueToItsProperType of TargetTemperature of Float "0.0" should be 0.0', ( ) =>
{
let accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.TargetTemperature;
let displayName = "testDevice";
let characteristicString = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type;
let format = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].props.format;
let value = "0.0";
let expectedResult = 0.0;
let expectedResultType = "number"; // There is no float type


let result = characteristicValueToItsProperType( console, format, displayName, Characteristic, characteristicString, value );

assert.equal( result, expectedResult, "configHasCharacteristicProps of valid data with full properties returned incorrect result: " + result );

let resultType = typeof result;

assert.equal( resultType, expectedResultType, "configHasCharacteristicProps of valid data with full properties returned incorrect result. Expected: : " + expectedResultType + " received: " + resultType );
});

it('characteristicValueToItsProperType of TargetTemperature of Float "0" should be float', ( ) =>
{
let accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.TargetTemperature;
let displayName = "testDevice";
let characteristicString = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].type;
let format = CMD4_ACC_TYPE_ENUM.properties[ accTypeEnumIndex ].props.format;
let value = "0";
let expectedResult = 0;
let expectedResultType = "number"; // There is no float type


let result = characteristicValueToItsProperType( console, format, displayName, Characteristic, characteristicString, value );

assert.equal( result, expectedResult, "configHasCharacteristicProps of valid data with full properties returned incorrect result: " + result );

let resultType = typeof result;

assert.equal( resultType, expectedResultType, "configHasCharacteristicProps of valid data with full properties returned incorrect result. Expected: : " + expectedResultType + " received: " + resultType );
});


it('characteristicValueToItsProperType of Name of string1 should be String.', ( ) =>
{
let accTypeEnumIndex = CMD4_ACC_TYPE_ENUM.Name;
Expand Down
27 changes: 26 additions & 1 deletion test/isNumeric.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,24 @@ describe( "Testing isNumeric", ( ) =>
assert.equal( result, expectedResult, "isNumeric( " + data + " ) returned: " + result + " expected: " + expectedResult );
});

it( "isNumeric should correctly identify a 0", ( ) =>
{
let data = 0;
let expectedResult = true;
let result = isNumeric( data );
assert.equal( result, expectedResult, "isNumeric( " + data + " ) returned: " + result + " expected: " + expectedResult );
});

it( `isNumeric should correctly identify a "0"`, ( ) =>
{
let data = "0";
let expectedResult = true;
let result = isNumeric( data );
assert.equal( result, expectedResult, "isNumeric( " + data + " ) returned: " + result + " expected: " + expectedResult );
});



it( "isNumeric should correctly fail a character string", ( ) =>
{
let data = "One";
Expand All @@ -57,12 +75,19 @@ describe( "Testing isNumeric", ( ) =>
assert.equal( result, expectedResult, "isNumeric( " + data + " ) returned: " + result + " expected: " + expectedResult );
});

it( "isNumeric should correctly fail a undefined", ( ) =>
it( "isNumeric should correctly fail an undefined", ( ) =>
{
let data = undefined;
let expectedResult = false;
let result = isNumeric( data );
assert.equal( result, expectedResult, "isNumeric( " + data + " ) returned: " + result + " expected: " + expectedResult );
});
it( "isNumeric should correctly fail a null", ( ) =>
{
let data = null;
let expectedResult = false;
let result = isNumeric( data );
assert.equal( result, expectedResult, "isNumeric( " + data + " ) returned: " + result + " expected: " + expectedResult );
});
})

0 comments on commit 019c6d2

Please sign in to comment.