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 class BoolExtensions { public static int i(this bool val) { return Convert.ToInt32(val); } } }
bool Or(bool i, bool j){ return (i+""+j).Contains("T");}bool And(bool i, bool j) {return !(i+""+j).Contains("F");}bool Xor(bool i, bool j){return i.CompareTo(j)*i.CompareTo(j)>0;}- 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 class BoolExtensions
- {
- public static int i(this bool val)
- {
- return 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.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)); } } }
// TODO: Replace examples and use TDD development by writing your own testsDescribe(AND_OR_XOR)- namespace Solution
- {
It(AND){Assert::That(And(true, false), Equals(false));Assert::That(And(false, true), Equals(false));Assert::That(And(true, true), Equals(true));Assert::That(And(false, false), Equals(false));}It(OR){Assert::That(Or(true, false), Equals(true));Assert::That(Or(false, true), Equals(true));Assert::That(Or(true, true), Equals(true));Assert::That(Or(false, false), Equals(false));}It(XOR){Assert::That(Xor(true, false), Equals(true));Assert::That(Xor(false, true), Equals(true));Assert::That(Xor(true, true), Equals(false));Assert::That(Xor(false, false), Equals(false));}};- 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.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));
- }
- }
- }