public static int MinusAddAngle(int input, AddSub addSub, int quantity) { if (addSub == AddSub.Add) { for (var i = 0; i < quantity; i++) { input++; if (input > 359) { input = 0; } } return(input); } if (addSub == AddSub.Sub) { for (var i = 0; i < quantity; i++) { input--; if (input < 0) { input = 359; } } return(input); } throw new InvalidEnumArgumentException("Wrong enum given to MinusAddAngle"); }
public void AddSubTest() { AddSub addSub = new AddSub(); int expected = 10; int actual = addSub.Cal_AddSub(5, 5); Assert.AreEqual(expected, actual); }
private static INode BuildSubNodes(INode lhs, TokenBuffer tokens) { var addSubOp = AddSubOp.Produce(tokens); if (addSubOp == null) return lhs; var rhs = MulDiv.Produce(tokens); if (rhs == null) { tokens.RestorePosition(); return lhs; } lhs = new AddSub(lhs, addSubOp, rhs); return BuildSubNodes(lhs, tokens); }
/// <summary> /// 代理 /// </summary> private static void testDelegate() { AddSub ass = new AddSub(); MulDiv md = new MulDiv(); Calculate add = new Calculate(ass.add); Calculate sub = new Calculate(ass.sub); Calculate mul = new Calculate(md.mul); Calculate div = new Calculate(md.div); Console.WriteLine("{0} + {1} = {2}", 2, 3, add(2, 3)); Console.WriteLine("{0} - {1} = {2}", 4, 5, sub(4, 5)); Console.WriteLine("{0} * {1} = {2}", 6, 7, mul(6, 7)); Console.WriteLine("{0} / {1} = {2}", 9, 3, div(9, 3)); //组合代理 Calculate cc = ass.add; cc += ass.sub;//add 和 sub都会执行 Console.WriteLine("{0} // {1} = {2}", 9, 3, cc(9, 3)); cc -= ass.sub;//去掉sub 只执行add方法 Console.WriteLine("{0} // {1} = {2}", 9, 3, cc(9, 3)); }