Beispiel #1
0
        static void Main(string[] args)
        {
            //Console.TreatControlCAsInput = true;
            Console.CancelKeyPress += (s, e) =>
            {
                e.Cancel = true;
                aborted  = true;
                Environment.Exit(0);
            };

            while (!aborted)
            {
                //Console.TreatControlCAsInput = true;
                Console.Write("> ");

                var input = Console.ReadLine();

                if (input == null)
                {
                    //Ctrl+C
                    break;
                }
                if (!long.TryParse(input, out var value))
                {
                    Console.WriteLine("Unable to parse user input!");
                    continue;
                }

                Console.WriteLine(PrettySize.Format(value, UnitBase.Base2));
                Console.WriteLine(PrettySize.Format(value, UnitBase.Base10));
            }
        }
Beispiel #2
0
 public void SingularVsPlural()
 {
     Assert.AreEqual("0 bytes", PrettySize.Format(0));
     Assert.AreEqual("0 bytes", PrettySize.Format(0, UnitBase.Base10));
     Assert.AreEqual("1 byte", PrettySize.Format(1));
     Assert.AreEqual("1 byte", PrettySize.Format(1, UnitBase.Base10));
     Assert.AreEqual("10 bytes", PrettySize.Format(10));
     Assert.AreEqual("10 bytes", PrettySize.Format(10, UnitBase.Base10));
     Assert.AreEqual("1.00 KiB", PrettySize.Format(1024));
     Assert.AreEqual("1.00 KB", PrettySize.Format(1000, UnitBase.Base10));
 }
Beispiel #3
0
 public void TestSingular()
 {
     Assert.AreEqual("0 bytes", PrettySize.Format(0));
     Assert.AreEqual("0 bytes", PrettySize.Format(0, CalculationBase.Base10));
     Assert.AreEqual("1 byte", PrettySize.Format(1));
     Assert.AreEqual("1 byte", PrettySize.Format(1, CalculationBase.Base10));
     Assert.AreEqual("10 bytes", PrettySize.Format(10));
     Assert.AreEqual("10 bytes", PrettySize.Format(10, CalculationBase.Base10));
     Assert.AreEqual("1.00 KiB", PrettySize.Format(1024));
     Assert.AreEqual("1.00 KB", PrettySize.Format(1000, CalculationBase.Base10));
 }
Beispiel #4
0
 public void Rounding()
 {
     Assert.AreEqual("1.50 KB", PrettySize.Format(1500, UnitBase.Base10));
     Assert.AreEqual("2.00 KB", PrettySize.Format(1999, UnitBase.Base10));
 }