Refactor: Separate concerns.
This commit is contained in:
140
Tests/Importer/ZaaImporter/LaurisItemTest.cs
Executable file
140
Tests/Importer/ZaaImporter/LaurisItemTest.cs
Executable file
@ -0,0 +1,140 @@
|
||||
/* LaurisItemTest.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using zaaReloaded2.LabModel;
|
||||
using zaaReloaded2.Importer.ZaaImporter;
|
||||
|
||||
namespace Tests.Importer.ZaaImporter
|
||||
{
|
||||
[TestFixture]
|
||||
class LaurisItemTest
|
||||
{
|
||||
[Test]
|
||||
[TestCase("Natrium: 139 [135 - 145] mmol/l", "Natrium", 139, "mmol/l", 135, 145, true)]
|
||||
[TestCase("Kalium: 5.2 [3.5 - 5] mmol/l", "Kalium", 5.2, "mmol/l", 3.5, 5, false)]
|
||||
public void ParseLaurisWithBothLimits(
|
||||
string laurisString, string name, double value,
|
||||
string unit, double lowerLimit, double upperLimit, bool isNormal)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(laurisString);
|
||||
Assert.AreEqual(name, i.Name, "Name");
|
||||
Assert.AreEqual(unit, i.Unit, "Unit");
|
||||
Assert.IsTrue(i.IsNumerical, "IsNumerical");
|
||||
Assert.AreEqual(value, i.NumericalValue, "NumericalValue");
|
||||
Assert.AreEqual(lowerLimit, i.LowerLimit, "Lower limit");
|
||||
Assert.AreEqual(upperLimit, i.UpperLimit, "Upper limit");
|
||||
Assert.AreEqual(isNormal, i.IsNormal, "IsNormal");
|
||||
Assert.IsTrue(i.HasLimits, "HasLimits");
|
||||
Assert.IsTrue(i.HasLowerLimit, "HasLowerLimit");
|
||||
Assert.IsTrue(i.HasUpperLimit, "HasUpperLimit");
|
||||
}
|
||||
|
||||
[TestCase("HDL - Cholesterin: 45 [>= 35] mg/dl", "HDL - Cholesterin", 45, "mg/dl", 35, true)]
|
||||
public void ParseLaurisWithLowerLimit(
|
||||
string laurisString, string name, double value,
|
||||
string unit, double lowerLimit, bool isNormal)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(laurisString);
|
||||
Assert.AreEqual(name, i.Name, "Name");
|
||||
Assert.AreEqual(unit, i.Unit, "Unit");
|
||||
Assert.IsTrue(i.IsNumerical, "IsNumerical");
|
||||
Assert.AreEqual(value, i.NumericalValue, "NumericalValue");
|
||||
Assert.AreEqual(lowerLimit, i.LowerLimit, "Lower limit");
|
||||
Assert.AreEqual(isNormal, i.IsNormal, "IsNormal");
|
||||
Assert.IsTrue(i.HasLimits, "HasLimits");
|
||||
Assert.IsTrue(i.HasLowerLimit, "HasLowerLimit");
|
||||
Assert.IsFalse(i.HasUpperLimit, "HasUpperLimit");
|
||||
}
|
||||
|
||||
[TestCase("GOT (ASAT): 303.0 [<= 50] U/l; ", "GOT (ASAT)", 303, "U/l", 50, false)]
|
||||
public void ParseLaurisWithUpperLimit(
|
||||
string laurisString, string name, double value,
|
||||
string unit, double upperLimit, bool isNormal)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(laurisString);
|
||||
Assert.AreEqual(name, i.Name, "Name");
|
||||
Assert.AreEqual(unit, i.Unit, "Unit");
|
||||
Assert.IsTrue(i.IsNumerical, "IsNumerical");
|
||||
Assert.AreEqual(value, i.NumericalValue, "NumericalValue");
|
||||
Assert.AreEqual(upperLimit, i.UpperLimit, "Upper limit");
|
||||
Assert.AreEqual(isNormal, i.IsNormal, "IsNormal");
|
||||
Assert.IsTrue(i.HasLimits, "HasLimits");
|
||||
Assert.IsFalse(i.HasLowerLimit, "HasLowerLimit");
|
||||
Assert.IsTrue(i.HasUpperLimit, "HasUpperLimit");
|
||||
}
|
||||
|
||||
[TestCase("Niedermol. Heparin (Anti-Xa): 0.99 U/ml;", "Niedermol. Heparin (Anti-Xa)", 0.99, "U/ml")]
|
||||
[TestCase("glomerul. Filtrationsr. CKD-EP: 42 ml/min /1,73qm;", "glomerul. Filtrationsr. CKD-EP", 42, "ml/min /1,73qm")]
|
||||
public void ParseLaurisWithoutLimits(
|
||||
string laurisString, string name, double value,
|
||||
string unit)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(laurisString);
|
||||
Assert.AreEqual(name, i.Name, "Name");
|
||||
Assert.AreEqual(unit, i.Unit, "Unit");
|
||||
Assert.IsTrue(i.IsNumerical, "IsNumerical");
|
||||
Assert.AreEqual(value, i.NumericalValue, "NumericalValue");
|
||||
Assert.IsFalse(i.HasLimits, "HasLimits");
|
||||
Assert.IsFalse(i.HasLowerLimit, "HasLowerLimit");
|
||||
Assert.IsFalse(i.HasUpperLimit, "HasUpperLimit");
|
||||
}
|
||||
|
||||
[TestCase("HBs-Antigen: neg. ;", "HBs-Antigen", "neg.")]
|
||||
public void ParseLaurisNonNumericNoNormal(
|
||||
string laurisString, string name, string value)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(laurisString);
|
||||
Assert.AreEqual(name, i.Name, "Name");
|
||||
Assert.AreEqual(value, i.Value, "Value");
|
||||
Assert.IsTrue(String.IsNullOrEmpty(i.Unit), "Unit should be a null string");
|
||||
Assert.IsFalse(i.HasLimits, "HasLimits");
|
||||
Assert.IsFalse(i.HasLowerLimit, "HasLowerLimit");
|
||||
Assert.IsFalse(i.HasUpperLimit, "HasUpperLimit");
|
||||
// TODO: Define the behavior of LaurisItem.IsNormal if no normal value known
|
||||
}
|
||||
|
||||
[TestCase("Erythrozyten (U): + [negativ]", "Erythrozyten (U)", "+", "negativ", false)]
|
||||
[TestCase("Bilirubin (U): negativ [negativ]", "Bilirubin (U)", "negativ", "negativ", true)]
|
||||
public void ParseLaurisNonNumericWithNormal(
|
||||
string laurisString, string name, string value, string normal, bool isNormal)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(laurisString);
|
||||
Assert.AreEqual(name, i.Name, "Name");
|
||||
Assert.AreEqual(value, i.Value, "Value");
|
||||
Assert.AreEqual(normal, i.Normal, "Normal");
|
||||
Assert.AreEqual(isNormal, i.IsNormal, "IsNormal");
|
||||
Assert.IsFalse(i.HasLimits, "HasLimits");
|
||||
Assert.IsFalse(i.HasLowerLimit, "HasLowerLimit");
|
||||
Assert.IsFalse(i.HasUpperLimit, "HasUpperLimit");
|
||||
// TODO: Define the behavior of LaurisItem.IsNormal if no normal value known
|
||||
}
|
||||
|
||||
[TestCase("Albumin (SU)/die: 149.9 [<= 30] mg/d; ", Material.SU)]
|
||||
[TestCase("Gesamt-Eiweiss/Creatinin (PU): 281 [<= 70] mg/g Crea;", Material.U)]
|
||||
[TestCase("Cystatin C (N Latex): 2.37 [0.57 - 0.96] mg/l; ", Material.B)]
|
||||
public void ParseLaurisMaterial(string laurisString, Material expectedMaterial)
|
||||
{
|
||||
LaurisItem i = new LaurisItem(laurisString);
|
||||
Assert.AreEqual(expectedMaterial, i.Material);
|
||||
}
|
||||
}
|
||||
}
|
46
Tests/Importer/ZaaImporter/LaurisParagraphTest.cs
Executable file
46
Tests/Importer/ZaaImporter/LaurisParagraphTest.cs
Executable file
@ -0,0 +1,46 @@
|
||||
/* LaurisParagraphTest.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using NUnit.Framework;
|
||||
using zaaReloaded2.LabModel;
|
||||
using zaaReloaded2.Importer.ZaaImporter;
|
||||
|
||||
namespace Tests.Importer.ZaaImporter
|
||||
{
|
||||
[TestFixture]
|
||||
class LaurisParagraphTest
|
||||
{
|
||||
[Test]
|
||||
public void ParseParagraph()
|
||||
{
|
||||
string demo = "Klinische Chemie: Natrium: 139 [135 - 145] mmol/l; " +
|
||||
"Kalium: 5.2 [3.5 - 5] mmol/l; Calcium: 2.4 [2.0 - 2.7] mmol/l;";
|
||||
LaurisParagraph lp = new LaurisParagraph(demo);
|
||||
Assert.IsTrue(lp.IsLaurisParagraph);
|
||||
Assert.AreEqual(139, lp.Items["Natrium"].NumericalValue);
|
||||
Assert.AreEqual(2.4, lp.Items["Calcium"].NumericalValue);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseInvalidParagraph()
|
||||
{
|
||||
string demo = "Aktuelle Diagnosen:";
|
||||
LaurisParagraph lp = new LaurisParagraph(demo);
|
||||
Assert.IsFalse(lp.IsLaurisParagraph);
|
||||
}
|
||||
}
|
||||
}
|
67
Tests/Importer/ZaaImporter/TimePointTest.cs
Executable file
67
Tests/Importer/ZaaImporter/TimePointTest.cs
Executable file
@ -0,0 +1,67 @@
|
||||
/* LaurisTimePointTest.cs
|
||||
* part of zaaReloaded2
|
||||
*
|
||||
* Copyright 2015 Daniel Kraus
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using NUnit.Framework;
|
||||
using zaaReloaded2.LabModel;
|
||||
using zaaReloaded2.Importer.ZaaImporter;
|
||||
|
||||
namespace Tests.Importer.ZaaImporter
|
||||
{
|
||||
[TestFixture]
|
||||
class LaurisTimePointTest
|
||||
{
|
||||
[Test]
|
||||
public void ParseValidLaurisTimePoint()
|
||||
{
|
||||
LaurisTimePoint tp = new LaurisTimePoint(
|
||||
"[22.10.2013 12:30:00]" + Environment.NewLine +
|
||||
"Klinische Chemie: Natrium: 139 [135 - 145] mmol/l; Kalium: 5.2 [3.5 - 5] mmol/l;");
|
||||
Assert.IsTrue(tp.IsValidTimePoint);
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseInvalidLaurisTimePoints()
|
||||
{
|
||||
LaurisTimePoint tp = new LaurisTimePoint("Aerobe Kultur: Enterokokken ; Wachstum: 10 ;");
|
||||
Assert.IsFalse(tp.IsValidTimePoint,
|
||||
"Bogus paragraph should be invalid LaurisTimePoint");
|
||||
|
||||
tp.LaurisText = "[22.10.2013 12:30:00]";
|
||||
Assert.IsFalse(tp.IsValidTimePoint,
|
||||
"LaurisTimePoint should be invalid if it consists of time stamp only.");
|
||||
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void ParseLaurisTimePointWithDuplicateItems()
|
||||
{
|
||||
LaurisTimePoint tp = new LaurisTimePoint(
|
||||
"[22.10.2013 12:30:00]" + Environment.NewLine +
|
||||
"Klinische Chemie: Natrium: 139 [135 - 145] mmol/l; Kalium: 5.2 [3.5 - 5] mmol/l;" + Environment.NewLine +
|
||||
"Klinische Chemie: Natrium: 142 [135 - 145] mmol/l; Kalium: 3.7 [3.5 - 5] mmol/l;"
|
||||
);
|
||||
Assert.IsTrue(tp.Items.ContainsKey("Kalium"),
|
||||
"LaurisTimePoint should contain 'Kalium' item.");
|
||||
Assert.AreEqual(3.7, tp.Items["Kalium"].NumericalValue,
|
||||
"LaurisTimePoint does not use last occurrence of 'Kalium'.");
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user