public void Abst_ShouldReturnAbsoluteValues() { // Arrange sbyte aByte = -10; short aShort = -20; int aInt = -30; long aLong = -40; float aFloat = -50.0F; double aDouble = -60.0; decimal aDecimal = (decimal) - 70.0; // Act short absByte = aByte.Abs(); short absShort = aShort.Abs(); int absInt = aInt.Abs(); long absLong = aLong.Abs(); float absFloat = aFloat.Abs(); double absDouble = aDouble.Abs(); decimal absDecimal = aDecimal.Abs(); // Assert Assert.Equal(10, absByte); Assert.Equal(20, absShort); Assert.Equal(30, absInt); Assert.Equal(40, absLong); Assert.Equal(50, absFloat); Assert.Equal(60, absDouble); Assert.Equal(70, absDecimal); }
public void Abs_ShouldBehaveAsMathAbs_IfShort(short value) => Assert.Equal(Math.Abs(value), value.Abs());
/// <summary> /// Function to return a formatted string containing the memory amount. /// </summary> /// <param name="amount">Amount of memory in bytes to format.</param> /// <returns>A string containing the formatted amount of memory in kilobytes.</returns> /// <remarks> /// This will produce a string value with the number of bytes suffixed with the word 'bytes' if less than 1023, or the number of kilobytes suffixed with the abbreviation 'KB' if the value is above 1023. /// <code language="csharp"> /// short bytes = 999; /// short kilobytes = 2048; /// /// Console.WriteLine(bytes.FormatMemory()); /// Console.WriteLine(kilobytes.FormatMemory()); /// /// // Produces: "128 bytes" and "2.0 KB". /// </code> /// </remarks> public static string FormatMemory(this short amount) { double scale = amount.Abs() / 1024.0; return(GetCultureString(scale >= 1.0 ? scale : amount, scale >= 1.0 ? Resources.GOR_UNIT_MEM_KB : Resources.GOR_UNIT_MEM_BYTES, false)); }