1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
|
// created on 3/8/2005 at 5:19 PM
/*
* Copyright (c) 2005, Alexandros Frantzis (alf82 [at] freemail [dot] gr)
*
* This file is part of Bless.
*
* Bless is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* Bless is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Bless; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
using NUnit.Framework;
using System;
using Bless.Util;
namespace BlessTests.Util {
[TestFixture]
public class BaseConverterTests
{
[Test]
public void BaseConverterTest1()
{
string s2 = BaseConverter.ConvertToString(15464, 2);
string s8 = BaseConverter.ConvertToString(15464, 8);
string s10 = BaseConverter.ConvertToString(15464, 10);
string s16 = BaseConverter.ConvertToString(15464, 16);
Assert.AreEqual("11110001101000", s2, "#base2");
Assert.AreEqual("36150", s8, "#base8");
Assert.AreEqual("15464", s10, "#base10");
Assert.AreEqual("3C68", s16, "#base16");
}
[Test]
public void BaseConverterTest2()
{
long l2 = BaseConverter.ConvertToNum("11110001101000", 2);
long l8 = BaseConverter.ConvertToNum("36150", 8);
long l10 = BaseConverter.ConvertToNum("15464", 10);
long l16 = BaseConverter.ConvertToNum("3C68", 16);
Assert.AreEqual(15464, l2, "#base2");
Assert.AreEqual(15464, l8, "#base8");
Assert.AreEqual(15464, l10, "#base10");
Assert.AreEqual(15464, l16, "#base16");
}
[Test]
[ExpectedException(typeof(FormatException))]
public void BaseConverterTest3()
{
BaseConverter.ConvertToNum("18032", 8);
}
[Test]
[ExpectedException(typeof(FormatException))]
public void BaseConverterTest4()
{
BaseConverter.ConvertToNum("a04zd", 16);
}
[Test]
public void BaseConverterTest5()
{
long l16 = BaseConverter.Parse(" 0x66 ");
long l10 = BaseConverter.Parse(" 66 ");
long l8 = BaseConverter.Parse(" 066 ");
Assert.AreEqual(0x66, l16, "#base16");
Assert.AreEqual(66, l10, "#base10");
Assert.AreEqual(54, l8, "#base8");
}
}
} // end namespace
|