public void BinOpTest() { CStack cs = new CStack(); cs.entry = "5"; cs.Enter(); cs.entry = "5"; cs.Enter(); cs.BinOp("+"); Assert.AreEqual(cs.X, 10); CStack cs2 = new CStack(); cs2.entry = "15"; cs2.Enter(); cs2.entry = "5"; cs2.Enter(); cs2.BinOp("-"); Assert.AreEqual(cs2.X, 5); CStack cs3 = new CStack(); cs3.entry = "2"; cs3.Enter(); cs3.entry = "5"; cs3.Enter(); cs3.BinOp("*"); Assert.AreEqual(cs3.X, 5); CStack cs4 = new CStack(); cs4.entry = "10"; cs4.Enter(); cs4.entry = "2"; cs4.Enter(); cs4.BinOp("÷"); Assert.AreEqual(cs4.X, 5); CStack cs5 = new CStack(); cs5.entry = "5"; cs5.Enter(); cs5.entry = "2"; cs5.Enter(); cs5.BinOp("yˣ"); Assert.AreEqual(cs5.X, 25); CStack cs6 = new CStack(); cs6.entry = "9"; cs6.Enter(); cs6.entry = "2"; cs6.Enter(); cs6.BinOp("ˣ√y"); Assert.AreEqual(cs6.X, 3); }
public void DropTest() { CStack cs = new CStack(); cs.entry = "1"; cs.Enter(); cs.entry = "2"; cs.Enter(); cs.entry = "3"; cs.Enter(); cs.entry = "4"; cs.Enter(); cs.Drop(); Assert.AreEqual(cs.X, 3); Assert.AreEqual(cs.Y, 2); Assert.AreEqual(cs.Z, 1); Assert.AreEqual(cs.T, 0); }
public void EnterTest() { CStack cs = new CStack(); cs.entry = "5"; cs.Enter(); Assert.AreEqual(cs.X, 5); Assert.AreEqual(cs.entry, ""); }
public void GetVarTest() { CStack cs = new CStack(); cs.entry = "1"; cs.Enter(); cs.SetAddress("A"); cs.SetVar(); cs.entry = "2"; cs.Enter(); cs.SetAddress("B"); cs.SetVar(); cs.entry = "3"; cs.Enter(); cs.SetAddress("C"); cs.SetVar(); cs.entry = "4"; cs.Enter(); cs.SetAddress("D"); cs.SetVar(); cs.entry = "5"; cs.Enter(); cs.SetAddress("E"); cs.SetVar(); cs.entry = "6"; cs.Enter(); cs.SetAddress("F"); cs.SetVar(); cs.entry = "7"; cs.Enter(); cs.SetAddress("G"); cs.SetVar(); cs.entry = "8"; cs.Enter(); cs.SetAddress("H"); cs.SetVar(); cs.GetVar(); Assert.AreEqual(cs.address[0, 1], "1"); Assert.AreEqual(cs.address[1, 1], "2"); Assert.AreEqual(cs.address[2, 1], "3"); Assert.AreEqual(cs.address[3, 1], "4"); Assert.AreEqual(cs.address[4, 1], "5"); Assert.AreEqual(cs.address[5, 1], "6"); Assert.AreEqual(cs.address[6, 1], "7"); Assert.AreEqual(cs.address[7, 1], "8"); }
public void SetVarTest() { CStack cs = new CStack(); cs.entry = "20"; cs.Enter(); cs.SetAddress("A"); cs.SetVar(); Assert.AreEqual(cs.address[0, 1], "20"); }
public void RollSetXTest() { CStack cs = new CStack(); cs.entry = "1"; cs.Enter(); cs.entry = "2"; cs.Enter(); cs.entry = "3"; cs.Enter(); Assert.AreEqual(cs.T, 0); Assert.AreEqual(cs.Z, 1); Assert.AreEqual(cs.Y, 2); Assert.AreEqual(cs.X, 3); cs.RollSetX(4); Assert.AreEqual(cs.T, 1); Assert.AreEqual(cs.Z, 2); Assert.AreEqual(cs.Y, 3); Assert.AreEqual(cs.X, 4); }
public void EntryChangeSignTest() { CStack cs = new CStack(); cs.entry = "5"; cs.EntryChangeSign(); Assert.AreEqual(cs.entry, "-5"); cs.EntryChangeSign(); Assert.AreEqual(cs.entry, "+5"); cs.entry = "5"; cs.Enter(); cs.EntryChangeSign(); Assert.AreEqual(cs.entry, "-"); }
private void EnterBtnClick(object sender, RoutedEventArgs e) { cs.Enter(); UpdateNumberField(); }
public void UnopTest() { // Powers & Logarithms: CStack cs = new CStack(); cs.entry = "5"; cs.Enter(); cs.Unop("x²"); Assert.AreEqual(cs.X, 25); CStack cs2 = new CStack(); cs2.entry = "25"; cs2.Enter(); cs2.Unop("√x"); Assert.AreEqual(cs2.X, 5); CStack cs3 = new CStack(); cs3.entry = "22"; cs3.Enter(); cs3.Unop("log x"); Assert.AreEqual(cs3.X, 1, 34242268082221); CStack cs4 = new CStack(); cs4.entry = "10"; cs4.Enter(); cs4.Unop("ln x"); Assert.AreEqual(cs4.X, 2, 30258509299405); CStack cs5 = new CStack(); cs5.entry = ""; cs5.Enter(); cs5.Unop("10ˣ"); Assert.AreEqual(cs5.X, 1); CStack cs6 = new CStack(); cs6.entry = "0"; cs6.Enter(); cs6.Unop("eˣ"); Assert.AreEqual(cs6.X, 1); // Trigonometry: CStack cs7 = new CStack(); cs7.entry = "10"; cs7.Enter(); cs7.Unop("sin"); Assert.AreEqual(cs7.X, -0, 54402111088937); CStack cs8 = new CStack(); cs8.entry = "15"; cs8.Enter(); cs8.Unop("cos"); Assert.AreEqual(cs8.X, -0, 759687912858821); CStack cs9 = new CStack(); cs9.entry = "20"; cs9.Enter(); cs9.Unop("tan"); Assert.AreEqual(cs9.X, 2, 23716094422474); CStack cs10 = new CStack(); cs10.entry = "0,10"; cs10.Enter(); cs10.Unop("sin⁻¹"); Assert.AreEqual(cs10.X, 0, 10016742116156); CStack cs11 = new CStack(); cs11.entry = "0,10"; cs11.Enter(); cs11.Unop("cos⁻¹"); Assert.AreEqual(cs11.X, 1, 47062890563334); CStack cs12 = new CStack(); cs12.entry = "0,10"; cs12.Enter(); cs12.Unop("tan⁻¹"); Assert.AreEqual(cs12.X, 0, 099668652491162); }
static void Main(string[] args) { CStack cs; cs = new CStack(); bool stop = false; Console.WriteLine("Welcome to ConsoleCalc"); string input; string[] commands; do { Console.Write("> "); input = Console.ReadLine(); commands = input.Split(' '); if (commands[0] == "quit") { Console.WriteLine("Bye! Press any key to continue ..."); stop = true; } else if (commands[0] == "enter" && commands.Length == 2) { cs.entry = commands[1]; cs.Enter(); } else if (commands[0] == "+") { cs.BinOp("+"); } else if (commands[0] == "*") { cs.BinOp("×"); } else if (commands[0] == "-") { cs.BinOp("−"); } else if (commands[0] == "/") { cs.BinOp("÷"); } else if (commands[0] == "/") { cs.BinOp("÷"); } else if (commands[0] == "^") { cs.BinOp("yˣ"); } else if (commands[0] == @"\") { cs.BinOp("ˣ√y"); } else if (commands[0] == "sqr") { cs.Unop("x²"); } else if (commands[0] == "sqrt") { cs.Unop("√x"); } else if (commands[0] == "log") { cs.Unop("log x"); } else if (commands[0] == "ln") { cs.Unop("ln x"); } else if (commands[0] == "10^") { cs.Unop("10ˣ"); } else if (commands[0] == "e^") { cs.Unop("eˣ"); } else if (commands[0] == "sin") { cs.Unop("sin"); } else if (commands[0] == "cos") { cs.Unop("cos"); } else if (commands[0] == "tan") { cs.Unop("tan"); } else if (commands[0] == "asin") { cs.Unop("sin⁻¹"); } else if (commands[0] == "acos") { cs.Unop("cos⁻¹"); } else if (commands[0] == "atan") { cs.Unop("tan⁻¹"); } else if (commands[0] == "pi") { cs.Nilop("π"); } else if (commands[0] == "e") { cs.Nilop("e"); } else if (commands[0] == "show") { Show(cs); } else { Console.WriteLine("Unknown command: {0}", commands[0]); } } while (!stop); Console.ReadKey(); }