Permalink
Browse files

BitTypeValue with tests (ParseString)

  • Loading branch information...
1 parent 44125f8 commit 3442184988f05c89842db61cb1e80e2081cc0632 @ajlopez committed Jul 17, 2011
Showing with 71 additions and 0 deletions.
  1. +24 −0 AjVars.Tests/TypeValueTests.cs
  2. +1 −0 AjVars/AjVars.csproj
  3. +46 −0 AjVars/BitTypeValue.cs
@@ -114,5 +114,29 @@ public void ShortToAndFromMemory()
type.ToMemory(memory, 30, Int16.MinValue);
Assert.AreEqual(Int16.MinValue, type.FromMemory(memory, 30));
}
+
+ [TestMethod]
+ public void ParseBitTypeValueFromBooleanString()
+ {
+ TypeValue type = new BitTypeValue();
+
+ Assert.AreEqual(false, type.ParseString("false"));
+ Assert.AreEqual(true, type.ParseString("true"));
+
+ Assert.AreEqual(false, type.ParseString("False"));
+ Assert.AreEqual(true, type.ParseString("True"));
+
+ Assert.AreEqual(false, type.ParseString("FALSE"));
+ Assert.AreEqual(true, type.ParseString("TRUE"));
+ }
+
+ [TestMethod]
+ public void ParseBitTypeValueFromZeroOneString()
+ {
+ TypeValue type = new BitTypeValue();
+
+ Assert.AreEqual(false, type.ParseString("0"));
+ Assert.AreEqual(true, type.ParseString("1"));
+ }
}
}
View
@@ -46,6 +46,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="Alarm.cs" />
+ <Compile Include="BitTypeValue.cs" />
<Compile Include="ByteMemory.cs" />
<Compile Include="ShortTypeValue.cs" />
<Compile Include="IntegerTypeValue.cs" />
View
@@ -0,0 +1,46 @@
+namespace AjVars
+{
+ using System;
+ using System.Collections.Generic;
+ using System.Linq;
+ using System.Text;
+
+ public class BitTypeValue : TypeValue
+ {
+ public override short Size
+ {
+ get { throw new NotImplementedException(); }
+ }
+
+ public override object FromMemory(ByteMemory memory, int address)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override void ToMemory(ByteMemory memory, int address, object obj)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override object ParseString(string text)
+ {
+ if ("0".Equals(text))
+ return false;
+
+ if ("1".Equals(text))
+ return true;
+
+ return Boolean.Parse(text);
+ }
+
+ public override byte[] ToBytes(object obj)
+ {
+ throw new NotImplementedException();
+ }
+
+ public override object FromBytes(byte[] bytes)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}

0 comments on commit 3442184

Please sign in to comment.