Skip to content

Commit

Permalink
Fix handling of numeric- and string representations of enums
Browse files Browse the repository at this point in the history
  • Loading branch information
javagl committed Oct 1, 2023
1 parent 60ca382 commit f6d0d7b
Show file tree
Hide file tree
Showing 14 changed files with 611 additions and 41 deletions.
72 changes: 72 additions & 0 deletions specs/metadata/MetadataEntityModelSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ describe("metadata/MetadataEntityModel", function () {
const testMetadataClass: MetadataClass = {
properties: {},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: 1234,
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
entity.getPropertyValue("testProperty");
Expand All @@ -34,11 +36,13 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: undefined,
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -56,17 +60,69 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: 2345,
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
expect(value).toBe(1234);
});

it("obtains a default value for an enum noData value", function () {
const testMetadataClass: MetadataClass = {
properties: {
testProperty: {
type: "ENUM",
enumType: "testEnum",
noData: "TEST_NO_DATA_ENUM_VALUE",
default: "TEST_DEFAULT_ENUM_VALUE",
},
},
};
const testMetadataEnums = {
testEnum: {
valueType: "UINT8",
values: [
{
name: "TEST_NO_DATA_ENUM_VALUE",
value: 255,
},
{
name: "TEST_ENUM_VALUE_A",
value: 1,
},
{
name: "TEST_ENUM_VALUE_B",
value: 2,
},
{
name: "TEST_ENUM_VALUE_C",
value: 3,
},
{
name: "TEST_DEFAULT_ENUM_VALUE",
value: 4,
},
],
},
};
const entityJson = {
testProperty: "TEST_NO_DATA_ENUM_VALUE",
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
expect(value).toBe("TEST_DEFAULT_ENUM_VALUE");
});

it("obtains a value for a vec3 float32 value with offset in property definition", function () {
const testMetadataClass: MetadataClass = {
properties: {
Expand All @@ -77,11 +133,13 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: [3.0, 4.0, 5.0],
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -99,11 +157,13 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: [3.0, 4.0, 5.0],
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -122,11 +182,13 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: [3.0, 4.0, 5.0],
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -148,8 +210,10 @@ describe("metadata/MetadataEntityModel", function () {
testProperty: [3.0, 4.0, 5.0],
scale: [2.0, 3.0, 4.0],
};
const testMetadataEnums = {};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -167,12 +231,14 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: [3.0, 4.0, 5.0],
offset: [1.0, 2.0, 3.0],
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -190,12 +256,14 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: [3.0, 4.0, 5.0],
offset: [1.0, 2.0, 3.0],
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -213,12 +281,14 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: [3.0, 4.0, 5.0],
scale: [2.0, 3.0, 4.0],
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand All @@ -237,13 +307,15 @@ describe("metadata/MetadataEntityModel", function () {
},
},
};
const testMetadataEnums = {};
const entityJson = {
testProperty: [3.0, 4.0, 5.0],
offset: [1.0, 2.0, 3.0],
scale: [2.0, 3.0, 4.0],
};
const entity = MetadataEntityModels.createFromClass(
testMetadataClass,
testMetadataEnums,
entityJson
);
const value = entity.getPropertyValue("testProperty");
Expand Down
2 changes: 1 addition & 1 deletion specs/metadata/PropertyTableModelsSpec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { ClassProperty } from "../../src/structure/Metadata/ClassProperty";
* - They check whether the elements of the input data and the
* values from the entity model are generically equal.
*/
describe("metadata/PropertyTableModelSpec", function () {
describe("metadata/PropertyTableModelsSpec", function () {
const epsilon = 0.000001;

it("correctly represents example_INT16_SCALAR", function () {
Expand Down
Loading

0 comments on commit f6d0d7b

Please sign in to comment.