context: using System;
  using NUnit.Framework;
  
  namespace NetChris.Tests.Core
  {
      /// <summary>
      /// Tests for the Base32 class
      /// </summary>
      [TestFixture]
      public class Base32Tests
      {
          [Test]
          public void TestBase32ToArgumentNullException()
          {
              const string badString = null;
  
              try
              {
                  Base32 testBase32 = badString;
                  Assert.Fail("This should not have succeeded. \"" + badString + "\" is invalid");
              }
              catch (ArgumentNullException)
              {
                  // Do nothing .. this is expected
              }
          }
  
          [Test]
          public void TestBase32ToArgumentOutOfRangeException()
          {
              string badString = string.Empty;
  
              try
              {
                  Base32 testBase32 = badString;
                  Assert.Fail("This should not have succeeded. \"" + badString + "\" is invalid");
              }
              catch (ArgumentOutOfRangeException)
              {
                  // Do nothing .. this is expected
              }
  
              badString = "        ";
  
              try
              {
                  Base32 testBase32 = badString;
                  Assert.Fail("This should not have succeeded. \"" + badString + "\" is invalid");
              }
              catch (ArgumentOutOfRangeException)
              {
                  // Do nothing .. this is expected
              }
          }
  
          [Test]
          public void TestBase32ToNumberFormatException01()
          {
              const string badString = "124D123=";
  
              try
              {
                  Base32 testBase32 = badString;
                  Assert.Fail("This should not have succeeded. \"" + badString + "\" is invalid");
              }
              catch (FormatException)
              {
                  // Do nothing .. this is expected
              }
          }
  
          [Test]
          public void TestBase32ToNumberFormatException02()
          {
              const string badString = "--33232Ff";
  
              try
              {
                  Base32 testBase32 = badString;
                  Assert.Fail("This should not have succeeded. \"" + badString + "\" is invalid");
              }
              catch (FormatException)
              {
                  // Do nothing .. this is expected
              }
          }
  
          [Test]
          public void TestEquals()
          {
              Base32 a = 334566;
              Base32 b1 = 334566;
              Base32 b2 = 8898923;
  
              var b = new object();
  
              // Test Base32 vs pure object
              Assert.IsFalse(a.Equals(b));
  
              // Test Base32 vs Base32 casted as object
              Assert.IsTrue(a.Equals((object)b1));
              Assert.IsFalse(a.Equals((object)b2));
          }
  
          [Test]
          public void TestEqualsBase32()
          {
              // ints
              Base32 a = 57878;
              Base32 b1 = 57878;
              Base32 b2 = 8898923;
  
              // longs
              Base32 x = 8236712873612867;
              Base32 y1 = 8236712873612867;
              Base32 y2 = 7236778773622267;
  
              Assert.IsTrue(a.Equals(b1));
              Assert.IsFalse(a.Equals(b2));
  
              Assert.IsTrue(x.Equals(y1));
              Assert.IsFalse(x.Equals(y2));
          }
  
          [Test]
          public void TestEqualsOnIntExtremities()
          {
              const int min = int.MinValue;
              const int max = int.MaxValue;
  
              Base32 minBase32 = min;
              Base32 maxBase32 = max;
  
              Assert.IsTrue(minBase32.Equals(min));
              Assert.IsTrue(maxBase32.Equals(max));
          }
  
          [Test]
          public void TestEqualsOnLongExtremities()
          {
              const long min = long.MinValue + 1;
              const long max = long.MaxValue;
  
              Base32 minBase32 = min;
              Base32 maxBase32 = max;
  
              Assert.IsTrue(minBase32.Equals(min));
              Assert.IsTrue(maxBase32.Equals(max));
          }
  
          [Test]
          public void TestEqualsOnShortExtremities()
          {
              const short min = short.MinValue;
              const short max = short.MaxValue;
  
              Base32 minBase32 = min;
              Base32 maxBase32 = max;
  
              Assert.IsTrue(minBase32.Equals(min));
              Assert.IsTrue(maxBase32.Equals(max));
          }
  
          [Test]
          public void TestFailureOnInvalidCharacters()
          {
              // Yes, I know this is crass, but it is a valid reason to use Base32
              // instead of Base32 and is what we are trying to avoid
              try
              {
                  Base32 obscenity = "23fuCK3Fc5n"; // Should fail because of the 'U'
                  Assert.Fail("This should not have succeeded", obscenity);
              }
              catch (FormatException fe)
              {
                  Console.WriteLine("Expected FormatException - message: \"{0}\"", fe.Message);
              }
  
              try
              {
                  Base32 obscenity = "57HshIT8F"; // Should fail because of the 'I'
                  Assert.Fail("This should not have succeeded", obscenity);
              }
              catch (FormatException fe)
              {
                  Console.WriteLine("Expected FormatException - message: \"{0}\"", fe.Message);
              }
          }
  
          [Test]
          public void TestIntEqualityOverload()
          {
              // ints
              Base32 a = 57878;
              Base32 b1 = 57878;
              Base32 b2 = 8898923;
  
              Assert.IsFalse(b2 == b1);
              Assert.IsFalse(b1 == b2);
              Assert.IsFalse(a == b2);
              Assert.IsFalse(b2 == a);
              Assert.IsTrue(a == b1);
              Assert.IsTrue(b1 == a);
          }
  
          [Test]
          public void TestIntInequalityOverload()
          {
              // ints
              Base32 a = 57878;
              Base32 b1 = 57878;
              Base32 b2 = 8898923;
  
              Assert.IsTrue(b2 != b1);
              Assert.IsTrue(b1 != b2);
              Assert.IsTrue(a != b2);
              Assert.IsTrue(b2 != a);
              Assert.IsFalse(a != b1);
              Assert.IsFalse(b1 != a);
          }
  
          [Test]
          public void TestKnownIntString()
          {
              // Flip-flop test a couple of known-good int/base32 pairs
  
              const int a = 765079618;
              const string b = "PSMC22";
  
              const int x = 492399830;
              const string y = "ENJV6P";
  
  
gt:             var base32 = new Base32(a);