2019-02-04 23:52:21 +00:00
|
|
|
|
// <copyright file="ChipUnitTest.cs" company="Adrian Conlon">
|
|
|
|
|
// Copyright (c) Adrian Conlon. All rights reserved.
|
|
|
|
|
// </copyright>
|
|
|
|
|
|
2019-04-21 03:47:36 +00:00
|
|
|
|
namespace EightBit
|
2019-02-03 00:42:55 +00:00
|
|
|
|
{
|
2019-02-04 23:52:21 +00:00
|
|
|
|
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
2019-02-03 00:42:55 +00:00
|
|
|
|
|
|
|
|
|
[TestClass]
|
|
|
|
|
public class ChipUnitTest
|
|
|
|
|
{
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestLowByte()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const ushort input = 0xf00f;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var low = Chip.LowByte(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xf, low);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestHighByte()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const ushort input = 0xf00f;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var high = Chip.HighByte(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xf0, high);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestClearFlag()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0xff;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.ClearFlag(flags, 0x80);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0x7f, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestClearFlagNonZero()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0xff;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.ClearFlag(flags, 0x80, 1);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0x7f, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestClearFlagZero()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0xff;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.ClearFlag(flags, 0x80, 0);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xff, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestClearFlagFalse()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0xff;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.ClearFlag(flags, 0x80, false);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xff, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestClearFlagTrue()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0xff;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.ClearFlag(flags, 0x80, true);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0x7f, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestSetFlag()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0x7f;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.SetFlag(flags, 0x80);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xff, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestSetFlagNonZero()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0x7f;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.SetFlag(flags, 0x80, 1);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xff, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestSetFlagZero()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0x7f;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.SetFlag(flags, 0x80, 0);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0x7f, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestSetFlagFalse()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0x7f;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.SetFlag(flags, 0x80, false);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0x7f, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestSetFlagTrue()
|
|
|
|
|
{
|
|
|
|
|
byte flags = 0x7f;
|
2019-02-03 10:23:41 +00:00
|
|
|
|
flags = Chip.SetFlag(flags, 0x80, true);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xff, flags);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestLowerPart()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const ushort input = 0xf00f;
|
2019-02-03 00:42:55 +00:00
|
|
|
|
ushort lower = Chip.LowerPart(input);
|
|
|
|
|
Assert.AreEqual(0xf, lower);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestHigherPart()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const ushort input = 0xf00f;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var higher = Chip.HigherPart(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xf000, higher);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestDemoteByte()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const ushort input = 0xf00f;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var demoted = Chip.DemoteByte(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xf0, demoted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestPromoteByte()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const byte input = 0xf0;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var promoted = Chip.PromoteByte(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xf000, promoted);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestLowNibble()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const byte input = 0xab;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var nibble = Chip.LowNibble(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xb, nibble);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestHighNibble()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const byte input = 0xab;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var nibble = Chip.HighNibble(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xa, nibble);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestDemoteNibble()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const byte input = 0xab;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var nibble = Chip.DemoteNibble(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xa, nibble);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestPromoteNibble()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const byte input = 0xab;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var nibble = Chip.PromoteNibble(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xb0, nibble);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestHigherNibble()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const byte input = 0xab;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var nibble = Chip.HigherNibble(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xa0, nibble);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestLowerNibble()
|
|
|
|
|
{
|
2019-02-19 00:56:16 +00:00
|
|
|
|
const byte input = 0xab;
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var nibble = Chip.LowerNibble(input);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xb, nibble);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[TestMethod]
|
|
|
|
|
public void TestMakeWord()
|
|
|
|
|
{
|
2019-04-21 03:47:36 +00:00
|
|
|
|
var word = Chip.MakeWord(0xcd, 0xab);
|
2019-02-03 00:42:55 +00:00
|
|
|
|
Assert.AreEqual(0xabcd, word);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|