C# 7.0+ features allow for syntatic sugar to reduce coding length. As well, the tests were using Is.Equal when Is.True and Is.False exist.
namespace Solution { using System; public static class logic { public static bool Or(bool i, bool j) => i.i() + j.i() >= 1; public static bool And(bool i, bool j) => i.i() + j.i() == 2; public static bool Xor(bool i, bool j) => i.i() + j.i() == 1; } public static class BoolExtensions { public static int i(this bool val) => Convert.ToInt32(val); } }
- namespace Solution
- {
- using System;
- public static class logic
- {
public static bool Or(bool i, bool j) { return i.i() + j.i() >= 1; }public static bool And(bool i, bool j) { return i.i() + j.i() == 2; }public static bool Xor(bool i, bool j) { return i.i() + j.i() == 1; }- public static bool Or(bool i, bool j) => i.i() + j.i() >= 1;
- public static bool And(bool i, bool j) => i.i() + j.i() == 2;
- public static bool Xor(bool i, bool j) => i.i() + j.i() == 1;
- }
- public static class BoolExtensions
- {
public static int i(this bool val){return Convert.ToInt32(val);}- public static int i(this bool val) => Convert.ToInt32(val);
- }
- }
namespace Solution { using NUnit.Framework; using System; using System.Collections.Generic; [TestFixture] public class Sample_Tests { [Test] public void AND() { Assert.That(logic.And(true, false), Is.False); Assert.That(logic.And(false, true), Is.False); Assert.That(logic.And(true, true), Is.True); Assert.That(logic.And(false, false), Is.False); } [Test] public void OR() { Assert.That(logic.Or(true, false), Is.True); Assert.That(logic.Or(false, true), Is.True); Assert.That(logic.Or(true, true), Is.True); Assert.That(logic.Or(false, false), Is.False); } [Test] public void XOR() { Assert.That(logic.Xor(true, false), Is.True); Assert.That(logic.Xor(false, true), Is.True); Assert.That(logic.Xor(true, true), Is.False); Assert.That(logic.Xor(false, false), Is.False); } } }
- namespace Solution
- {
- using NUnit.Framework;
- using System;
- using System.Collections.Generic;
- [TestFixture]
- public class Sample_Tests
- {
- [Test]
- public void AND()
- {
- Assert.That(logic.And(true, false), Is.False);
- Assert.That(logic.And(false, true), Is.False);
- Assert.That(logic.And(true, true), Is.True);
- Assert.That(logic.And(false, false), Is.False);
- }
[Test]public void AND(){Assert.That(logic.And(true, false), Is.EqualTo(false));Assert.That(logic.And(false, true), Is.EqualTo(false));Assert.That(logic.And(true, true), Is.EqualTo(true));Assert.That(logic.And(false, false), Is.EqualTo(false));}[Test]public void OR(){Assert.That(logic.Or(true, false), Is.EqualTo(true));Assert.That(logic.Or(false, true), Is.EqualTo(true));Assert.That(logic.Or(true, true), Is.EqualTo(true));Assert.That(logic.Or(false, false), Is.EqualTo(false));}[Test]public void XOR(){Assert.That(logic.Xor(true, false), Is.EqualTo(true));Assert.That(logic.Xor(false, true), Is.EqualTo(true));Assert.That(logic.Xor(true, true), Is.EqualTo(false));Assert.That(logic.Xor(false, false), Is.EqualTo(false));}- [Test]
- public void OR()
- {
- Assert.That(logic.Or(true, false), Is.True);
- Assert.That(logic.Or(false, true), Is.True);
- Assert.That(logic.Or(true, true), Is.True);
- Assert.That(logic.Or(false, false), Is.False);
- }
- [Test]
- public void XOR()
- {
- Assert.That(logic.Xor(true, false), Is.True);
- Assert.That(logic.Xor(false, true), Is.True);
- Assert.That(logic.Xor(true, true), Is.False);
- Assert.That(logic.Xor(false, false), Is.False);
- }
- }
}- }