6.4 KiB
source_files, generated_at, model, schema_version, sha256
| source_files | generated_at | model | schema_version | sha256 | |||
|---|---|---|---|---|---|---|---|
|
2026-04-16T03:45:54.975833+00:00 | Qwen/Qwen3-Coder-Next-FP8 | 1 | b51d16198cb266e3 |
SensorDB.Test
Documentation: SensorDB Module (Test-Focused)
This document describes the behavioral contract inferred from unit tests in the SensorDB.Tests project. It reflects expected public behaviors of core types in the DTS.SensorDB namespace, as verified by unit tests. Note: These are test-driven specifications, not implementation files; they define what the code must do, not how.
1. Purpose
This module provides core data structures and validation logic for sensor calibration metadata and related utilities, primarily used in data acquisition and processing pipelines. It includes types for representing calibration records (SensorCalibration, IsoCode, InitialOffset), supporting operations like compatibility checks (e.g., IEPE sensor compatibility), string formatting, and comparison. The tests validate behavior for edge cases (e.g., null/empty inputs, missing calibration data) to ensure robustness in downstream systems.
2. Public Interface
SensorData.GetInitialEUValue(ISensorCalibration calibration, ExcitationVoltageOptions.ExcitationVoltageOption excitation, InitialOffset initialOffset)
- Behavior: Retrieves the initial engineering unit (EU) value for a given excitation voltage, based on calibration data and an
InitialOffsetconfiguration. - Exceptions: Throws
NullReferenceExceptionwith message"No calibration record found for {ExcitationVoltage}"if noICalibrationRecordexists incalibration.Recordsmatching the specifiedexcitation. - Note: The test uses
ExcitationVoltageOption.Volt3while the mock only providesVolt2, triggering the exception.
IsoCode.TestObject { get; set; }
- Type:
string - Behavior:
- When set to
null, the property value becomes"?". - When set to
""(empty string), the property value becomes"?". - Otherwise, it stores and returns the assigned string value unchanged.
- When set to
IsoCode.StringRepresentation { get; }
- Type:
string - Behavior:
- Returns the raw
TestObjectvalue if it is non-null and non-empty. - If
TestObjectends before 16 characters, appends enough"?"characters to reach a total length of 16.- Example:
"??RIBS0200HF"(12 chars) →"??RIBS0200HF????"(16 chars).
- Example:
- If
TestObjectisnullor empty,StringRepresentationreturns"?"(inferred fromTestObjectbehavior and test expectations).
- Returns the raw
SensorCalibration.IsCompatibleWithIEPE()
- Return Type:
bool - Behavior:
- Returns
falseifIsProportionalistrue. - Returns
falseifNonLinearistrue. - Returns
trueonly if bothIsProportional == falseandNonLinear == false.
- Returns
SensorCalibration.ToNonLinearDisplayString(string value, bool force)
- Return Type:
string - Behavior:
- Returns
""(empty string) ifNonLinearisfalse. - Returns
""ifvalueisnull(regardless ofNonLinear). - (No tests confirm behavior when
NonLinear == trueandvalue != null; behavior unknown.)
- Returns
SensorCalibration.CompareTo(object obj)
- Return Type:
int(implementsIComparable) - Behavior:
- Returns
1ifobjisnull. - Returns
0ifobjis aSensorCalibrationwith the sameCalibrationDate. - Returns a non-zero value (negative or positive) if
CalibrationDatediffers (exact ordering not specified beyond non-zero). - Note: Only
CalibrationDateis used for comparison in the tests.
- Returns
3. Invariants
IsoCode.StringRepresentationis always exactly 16 characters long ifTestObjectis non-null and non-empty, padded with"?"to the right.IsoCode.TestObjectis nevernullor empty in its stored value; both are normalized to"?".SensorCalibration.IsCompatibleWithIEPE()istrueiff bothNonLinear == falseandIsProportional == false.SensorData.GetInitialEUValue(...)requires a matchingICalibrationRecordfor the givenexcitation; otherwise, it fails with aNullReferenceException(notArgumentExceptionorKeyNotFoundException).SensorCalibration.CompareTo(null)always returns1, indicatingthisinstance is "greater than"null.
4. Dependencies
- Internal Dependencies (inferred from test imports):
DTS.SensorDBnamespace (containsSensorData,SensorCalibration,IsoCode,InitialOffset,InitialOffsetTypes,ExcitationVoltageOptions,ISensorCalibration,ICalibrationRecord).DTS.Common.Interface.Sensors,DTS.Common.Enums,DTS.Common.Classes.Sensors,DTS.Common.Enums.Sensors(for sensor-related types).
- Test Frameworks:
NUnit(test runner/assertions).NSubstitute(mocking framework for interfaces likeISensorCalibration,ICalibrationRecord).
- No external runtime dependencies beyond .NET standard libraries and the above internal modules.
5. Gotchas
NullReferenceExceptionfor missing calibration data:SensorData.GetInitialEUValuethrowsNullReferenceException(not a more semantically appropriate exception likeKeyNotFoundExceptionorArgumentException) when no calibration record matches the requested excitation. This is a potential anti-pattern and may mislead developers expecting a domain-specific exception.IsoCodepadding behavior is implicit: The 16-character padding rule is only verified for theStringRepresentationproperty, but not explicitly documented in the source. Developers must infer that padding is applied only whenTestObjectis non-null/non-empty.ToNonLinearDisplayStringbehavior is underspecified: Tests cover only theNonLinear == falseorvalue == nullcases. Behavior whenNonLinear == trueandvalue != nullis unknown.CompareTouses onlyCalibrationDate: DespiteSensorCalibrationlikely having other fields (e.g., serial number, model), tests confirm comparison is based solely onCalibrationDate. This may cause unexpected ordering if other fields are expected to participate.- No tests for
SensorCalibrationequality (Equals/GetHashCode): WhileCompareTois tested, equality semantics are not verified — may differ from date-only comparison.
None identified beyond the above.