public void GivenValidHexChar_WhichIsUpperCase_AsCharReturnsSameCharAsLowerCase(char upperCaseHexChar) { var expectedHexChar = Char.ToLower(upperCaseHexChar); var hexDigit = new HexDigit(upperCaseHexChar); hexDigit.AsChar.Should().Be(expectedHexChar); }
public void GivenInvalidHexDigitArray_ConstructorShouldThrow_InvalidHexStringException() { var hexDigits = new HexDigit[] { new HexDigit('0') }; Action constructWithInvalidHexDigitArray = () => new HexString(hexDigits); constructWithInvalidHexDigitArray.ShouldThrow <InvalidHexStringException>(); }
public void GivenValidHexDigitArray_ConstructsExpectedHexString() { var hexDigits = new HexDigit[] { new HexDigit('0'), new HexDigit('f'), }; const string ExpectedHex = "0f"; var hexString = new HexString(hexDigits); hexString.Hex.Should().Be(ExpectedHex); }
public void GivenValidHex_IndexOperator_ReturnsExpectedHexDigits() { const string Hex = "0c9f"; var expectedHexDigits = new HexDigit[] { new HexDigit('0'), new HexDigit('c'), new HexDigit('9'), new HexDigit('f'), }; var hexString = new HexString(Hex); for (var i = 0; i < Hex.Length; ++i) { var expectedDigit = expectedHexDigits[i]; var actualDigit = hexString[i]; expectedDigit.AsChar.Should().Be(actualDigit.AsChar); expectedDigit.AsByte.Should().Be(actualDigit.AsByte); } }
public static char ToChar(this HexDigit src) { if (src == HexDigit.X0) { return(AsciDigits.A0); } else if (src == HexDigit.X1) { return(AsciDigits.A1); } else if (src == HexDigit.X2) { return(AsciDigits.A2); } else if (src == HexDigit.X3) { return(AsciDigits.A3); } else if (src == HexDigit.X4) { return(AsciDigits.A4); } else if (src == HexDigit.X5) { return(AsciDigits.A5); } else if (src == HexDigit.X6) { return(AsciDigits.A6); } else if (src == HexDigit.X7) { return(AsciDigits.A7); } else if (src == HexDigit.X8) { return(AsciDigits.A8); } else if (src == HexDigit.X9) { return(AsciDigits.A9); } else if (src == HexDigit.XA) { return(AsciLower.a); } else if (src == HexDigit.XB) { return(AsciLower.b); } else if (src == HexDigit.XC) { return(AsciLower.c); } else if (src == HexDigit.XD) { return(AsciLower.d); } else if (src == HexDigit.XE) { return(AsciLower.e); } else if (src == HexDigit.XF) { return(AsciLower.f); } else { return(MathSym.EmptySet); } }
public void GivenValidHexByte_AsByteReturnsExpectedByte(byte expectedHexByte) { var hexDigit = new HexDigit(expectedHexByte); hexDigit.AsByte.Should().Be(expectedHexByte); }
public void GivenValidHexByte_AsCharReturnsExpectedChar(byte hexByte, char expectedHexChar) { var hexDigit = new HexDigit(hexByte); hexDigit.AsChar.Should().Be(expectedHexChar); }
public void GivenValidHexChar_AsByteReturnsExpectedByte(char hexChar, byte expectedByte) { var hexDigit = new HexDigit(hexChar); hexDigit.AsByte.Should().Be(expectedByte); }
public void GivenValidHexChar_AsCharReturnsSameChar(char expectedHexChar) { var hexDigit = new HexDigit(expectedHexChar); hexDigit.AsChar.Should().Be(expectedHexChar); }