public void Test_1_plus_1_plus_1() { var res = Arithmetics.Add(true, true, true); res.High.Should().BeTrue(); res.Low.Should().BeTrue(); }
public void TestAgainMethodSum() { Arithmetics a = new Arithmetics(); Assert.AreEqual(15, a.Sum(new int[] { 1, 2, 3, 4, 5 })); }
} // End Property Slope // https://stackoverflow.com/questions/17692922/check-is-a-point-x-y-is-between-two-points-drawn-on-a-straight-line public bool IsPointOnLine(MyPoint2D <T> p) { T norm = this.Vector.MagnitudeSquared; MyVector2D <T> vec1 = new MyVector2D <T>(this.m_start, p); MyVector2D <T> vec2 = new MyVector2D <T>(this.m_end, p); T dist = Arithmetics <T> .Add(vec1.MagnitudeSquared, vec2.MagnitudeSquared); if (norm.Equals(dist)) { return(true); } T delta = Arithmetics <T> .Subtract(vec1.MagnitudeSquared, vec2.MagnitudeSquared); decimal decDelta = System.Convert.ToDecimal(delta); decDelta = System.Math.Abs(decDelta); // Greatest possible floating-point difference decimal decFloatEpsilon = System.Convert.ToDecimal(float.Epsilon); if (decDelta <= decFloatEpsilon) { return(true); } return(false); } // End Function IsPointOnLine
public void Test_1_plus_0() { var res = Arithmetics.HalfAdder(true, false); res.High.Should().BeFalse(); res.Low.Should().BeTrue(); }
protected float CalculateVelocityManeuver(float aVelocity) { float velocity = Arithmetics.KeepInRange(aVelocity, Min, Max); float diff = Diff(velocity) / 2; return(Arithmetics.KeepInRange(diff * Agression, Input.Limits.Pitch.Min, Input.Limits.Pitch.Max)); }
public void Test_0_plus_0_plus_0() { var res = Arithmetics.Add(false, false, false); res.High.Should().BeFalse(); res.Low.Should().BeFalse(); }
public void Test_0_plus_1() { var res = Arithmetics.HalfAdder(false, true); res.High.Should().BeFalse(); res.Low.Should().BeTrue(); }
/// <summary> /// Resamples data from multiple channels to single one. /// </summary> /// <param name="audio">audio with</param> public static short[] ConvertToMono(IAudioFormat audio) { if (audio == null) { throw new ArgumentNullException("Argument 'audio' is null."); } if (audio.Data == null) { throw new ArgumentNullException("Argument 'audio.Data' is null"); } switch (audio.Channels) { case 1: return(audio.Data); case 2: short[] mono = new short[audio.NumOfDataSamples / 2]; for (int i = 0; i < audio.NumOfDataSamples; i += 2) //4 bytes per loop are processed (2 left + 2 right samples) { mono[i / 2] = Arithmetics.Average(audio.Data[i], audio.Data[i + 1]); } return(mono); default: throw new NotImplementedException($"Convert from {audio.Channels} channels to mono is not supported."); } }
static void Main(string[] args) { Arithmetics add = x => x.Select(element => element + 1).ToArray(); Arithmetics mult = x => x.Select(element => element * 2).ToArray(); Arithmetics subtr = x => x.Select(element => element - 1).ToArray(); int[] inputNums = Console.ReadLine().Split().Select(int.Parse).ToArray(); string command; while ((command = Console.ReadLine()) != "end") { switch (command) { case "add": inputNums = add(inputNums); break; case "multiply": inputNums = mult(inputNums); break; case "subtract": inputNums = subtr(inputNums); break; case "print": Console.WriteLine(string.Join(' ', inputNums)); break; default: throw new ArgumentException("Invalid action!"); } } }
public void Minus_one_is_less_than_zero() { // Act var equalsZero = Arithmetics.IsLessThanZero(new Byte2(-1)); // Assert equalsZero.Should().BeTrue(); }
public MyVector3D(MyPoint3D <T> a, MyPoint3D <T> b) { this.X = Arithmetics <T> .Subtract(a.X, b.X); this.Y = Arithmetics <T> .Subtract(a.Y, b.Y); this.Z = Arithmetics <T> .Subtract(a.Z, b.Z); } // End Constructor
public void Test_1_plus_0_plus_1() { var res = Arithmetics.AddTwoBits(new Bit2(false, true), new Bit2(false, false), true); res.High.Low.Should().BeFalse(); res.Low.High.Should().BeTrue(); res.Low.Low.Should().BeFalse(); }
public void Test_0_plus_0_plus_0() { var nibble = Arithmetics.AddTwoBits(new Bit2(false, false), new Bit2(false, false), false); nibble.High.Low.Should().BeFalse(); nibble.Low.High.Should().BeFalse(); nibble.Low.Low.Should().BeFalse(); }
public void Minvalue_is_less_than_zero() { // Act var equalsZero = Arithmetics.IsLessThanZero(new Byte2(short.MinValue)); // Assert equalsZero.Should().BeTrue(); }
public void Zero_is_not_less_than_zero() { // Act var equalsZero = Arithmetics.IsLessThanZero(new Byte2(0)); // Assert equalsZero.Should().BeFalse(); }
public void Zero_equals_zero() { // Act var equalsZero = Arithmetics.EqualsZero(new Nibble(0)); // Assert equalsZero.Should().BeTrue(); }
} // End Function IsPointOnLine public static MyVector2D <T> ToVector(MyPoint2D <T> start, MyPoint2D <T> end) { T x = Arithmetics <T> .Subtract(end.X, start.X); T y = Arithmetics <T> .Subtract(end.Y, start.Y); return(new MyVector2D <T>(x, y)); } // End Function ToVector
public void Fifteen_does_not_equal_zero() { // Act var equalsZero = Arithmetics.EqualsZero(new Nibble(15)); // Assert equalsZero.Should().BeFalse(); }
} // End Property Normalized // http://mathworld.wolfram.com/NormalVector.html // https://stackoverflow.com/questions/1243614/how-do-i-calculate-the-normal-vector-of-a-line-segment public static MyVector2D <T> GetNormalVector(MyVector2D <T> vec) { MyVector2D <T> normal1 = new MyVector2D <T>(Arithmetics <T> .Minus(vec.Y), vec.X); // MyVector2D<T> normal2 = new MyVector2D<T>(vec.Y, Arithmetics<T>.Minus(vec.X)); return(normal1); } // End Function GetNormalVector
public IActionResult About() { int value1 = 2; int value2 = 2; ViewData["Message"] = string.Format("{0} + {1} = {2}", value1, value2, Arithmetics.Add(value1, value2)); return View(); }
public void Maxvalue_is_not_less_than_zero() { // Act var byte2 = new Byte2(short.MaxValue); var equalsZero = Arithmetics.IsLessThanZero(byte2); // Assert equalsZero.Should().BeFalse(); }
public void TestMethodSum() { Arithmetics a = new Arithmetics(); //a test composed out of two subtests Assert.AreEqual(23.5, a.Sum(13.5, 10)); Assert.AreEqual(23, a.Sum(13, 10)); }
} // End Function Schnittpunktli // https://en.wikipedia.org/wiki/Determinant // | a b | // | c d | private static T Determinant2d(T a, T b, T c, T d) { T f1 = Arithmetics <T> .Multiply(a, d); T f2 = Arithmetics <T> .Multiply(b, c); T result = Arithmetics <T> .Subtract(f1, f2); return(result); } // End Function Determinant2d
} // End Operator * public static MyVector2D <T> operator *(MyVector2D <T> a, T b) { MyVector2D <T> v = a.Clone(); v.X = Arithmetics <T> .Multiply(v.X, b); v.Y = Arithmetics <T> .Multiply(v.Y, b); return(v); } // End Operator *
} // End Operator + public static MyVector2D <T> operator -(MyVector2D <T> a, MyVector2D <T> b) { MyVector2D <T> v = a.Clone(); v.X = Arithmetics <T> .Subtract(v.X, b.X); v.Y = Arithmetics <T> .Subtract(v.Y, b.Y); return(v); } // End Operator -
} // End Operator + public static MyPoint2D <T> operator +(MyPoint2D <T> point, MyVector2D <T> a) { MyPoint2D <T> p = point.Clone(); p.X = Arithmetics <T> .Add(p.X, a.X); p.Y = Arithmetics <T> .Add(p.Y, a.Y); return(p); } // End Operator +
public void Test_MinValue_increment() { // Arrange var a = new Byte2(short.MinValue); // Act var byteResult = Arithmetics.Increment(a); // Assert byteResult.ToInt16().Should().Be(short.MinValue + 1); }
public void Test_0_increment() { // Arrange var a = new Byte2(0); // Act var byteResult = Arithmetics.Increment(a); // Assert byteResult.ToInt16().Should().Be(1); }
} // End function CrossP // The dot product (also called the scalar product) is the magnitude of // vector b multiplied by the size of the projection of a onto b. // The size of the projection is a cosθ (where θ is the angle between the 2 vectors). // https://coderwall.com/p/icvt-g/2d-vector-dot-product // where theta is the angle between u and v, given by the dot product // cos(theta) = u dotp v public static T DotP(MyVector2D <T> a, MyVector2D <T> b) { T s1 = Arithmetics <T> .Multiply(a.X, b.X); T s2 = Arithmetics <T> .Multiply(a.Y, b.Y); //A * B = ax*bx+ay*by+az*bz T retValue = Arithmetics <T> .Add(s1, s2); return(retValue); } // End function DotP
} // End Property NormalVector // http://mathworld.wolfram.com/CrossProduct.html // the cross product is a vector that is perpendicular to both // a and b and thus normal to the plane containing them // |u x v| = |u| x |v| * sin(phi) public static T CrossP(MyVector2D <T> a, MyVector2D <T> b) { // crossp = det(a,b) = a.X*b.Y- a.Y*b.X T s1 = Arithmetics <T> .Multiply(a.X, b.Y); T s2 = Arithmetics <T> .Multiply(a.Y, b.X); T retValue = Arithmetics <T> .Subtract(s1, s2); return(retValue); } // End function CrossP