public void PacActOnPerson_NoPerson() { var deviceMock = new Mock <IDevice>(); deviceMock.Setup(foo => foo.On()).Verifiable(); deviceMock.Setup(foo => foo.Off()).Verifiable(); deviceMock.Setup(foo => foo.Restore()).Verifiable(); var deivce = deviceMock.Object; var zoneMock = new Mock <Zone>(); zoneMock.Setup(foo => foo.InZone(It.IsAny <Person>())).Returns(false).Verifiable(); var zone = zoneMock.Object; var cal = new Cal(); cal.AddScenario(new Scenario { Devices = new HashSet <IDevice> { deivce }, Identifier = "mock1", Zone = zone }); cal.ActOnPeoplePresent(new List <Person>()); deviceMock.Verify(t => t.Restore(), Times.Never); deviceMock.Verify(t => t.Off(), Times.Once); deviceMock.Verify(t => t.On(), Times.Never); zoneMock.Verify(t => t.InZone(It.IsAny <Person>()), Times.Never); }
public PeriodicallyScheduledWorkItem(TState state, TimeSpan period, Func <TState, TState> action) { _state = state; _action = action; _cancel = Cal.StartPeriodicTimer(Tick, period); }
private void button1_Click(object sender, EventArgs e) { Cal cal = new Cal(); cal.Add(10, 20); MessageBox.Show(cal.Result.ToString()); }
private static bool parseDate(ref Context ctx, Cal calen, bool second = false) { // TODO according to standard, the calendar escape can go on each date, e.g. "AFT @#DJULIAN@ 1898" // parse a date. // TODO dd/mm/yyyy // TODO dd-mm-yyyy // day mon year : num word num // mon year : word num // year : num Token tok = ctx.LookAhead(); switch (tok.type) { case TokType.WORD: return(parseMonYear(ref ctx, calen, second)); case TokType.SYMB: return(parseSymAndDate(ref ctx, calen, second)); case TokType.NUM: return(parseDate2(ref ctx, calen, second)); default: return(false); } }
public ActionResult CalAction(Cal c) { ViewBag.Method = "POST"; //string remarks1 = ModelState["Remarks"].Value.AttemptedValue; //string remarks2 = c.Remarks; //string remarks3 = Request.Unvalidated.Form["remarks"]; //string remarks4 = Request.Form["remarks"]; //Request.Form will perform its own validation independent of the modal class, so this will error out even if AllowHtml is configured on the model if (ModelState.IsValid) { if (c.Remarks.Contains("ABC")) { ModelState.AddModelError("Remarks", "Cannnot contains ABC"); } else { c.Result = Convert.ToString(c.Input1 + c.Input2); UpdateSession(c); } } else { string err = "Something wrong in your inputs!"; ModelState.AddModelError("", err); } ViewBag.RecentCal = (string)Session["RecentCal"]; return(View(c)); }
private static bool getMonth(string str, Cal calen, ref int mon) { // TODO swap month lookup based on calendar // TODO may find month match in list for different calendar - change calendar? // TODO non-standard match needs flagging mechanism int monNum; if (gregMonNonStdLookup.TryGetValue(str, out monNum)) { mon = monNum; return(true); } if (str.Length < 3) { return(false); } string str2 = str.Substring(0, 3); if (gregMonLookup.TryGetValue(str2, out monNum)) { mon = monNum; return(true); } return(false); }
public void Result(bool check) //结果函数 { bool flag = true; //flag判断是否为无效输入 if (R1 <= 0 || R2 <= 0 || R3 <= 0 || R4 <= 0) { MessageBox.Show("输入无效,电阻不可为0或负数,请重新检查输入!"); flag = false; } if (vol <= 0) { MessageBox.Show("输入无效,电压不可为0或负数,请重新检查输入!"); flag = false; } //如果输入合法 if (check == true && flag == true) { res = 0; //调用计算函数得出结果I Cal result = new Cal(); res = result.Calculate(vol, R1, R2, R3, R4, check); } if (check == false && flag == true) { Cal result = new Cal(); res = result.Calculate(vol, R1, R2, R3, R4, check); } if (flag == false) { res = 0; //如果出错结果保持为0 } }
private static void DebugReport(TimeSlot[] ts, string item, Cal c) { string stud = item + "\t"; foreach (var tst in ts) { bool free = c.IsFreeOn(tst); bool bPossible = free; if (bPossible) { if (c.IsDayFree(tst.dayOfWeek)) bPossible = false; } if (bPossible) { int aft = c.ContinuousStretchAfter(tst); int bef = c.ContinuousStretchBefore(tst); int totSlot = aft + 2 + bef; if (totSlot > 4) bPossible = false; } if (bPossible) stud += "True\t"; else stud += "\t"; } Debug.WriteLine(stud); }
static void Main(string[] args) { ICalc c = new Cal(); int s = c.Add(2, 3); Console.WriteLine($"2+3={s}"); Console.ReadKey(); }
static void Main(string[] args) { Cal cal = new Cal(); Console.WriteLine(cal.Power(5)); Console.WriteLine(cal.Power(5, 3)); Console.WriteLine(cal.SumAll(3)); Console.WriteLine(cal.SumAll(1, 3)); }
static void Main(string[] args) { Cal cal = new Cal(); cal.setMass(90); Console.WriteLine(cal.getMass()); // Suspend the console. Console.ReadKey(); }
static void Main21(string [] args) { Cal cal = new Cal(); //인스턴스생성 Console.WriteLine("x + y = " + cal.Plus(4, 5)); //인스턴스 메서드 호출 Console.WriteLine(); cal.Print("홍길동"); cal.Print(); }
public void TestAdd() { ICalc c = new Cal(); int expected = 5; int actual = c.Add(2, 3); Assert.AreEqual(expected, actual); }
public void TestSub() { ICalc c = new Cal(); int expected = 0; int actual = c.Sub(-5, -5); Assert.AreEqual(expected, actual); }
public void TestMul() { ICalc c = new Cal(); int expected = 50; int actual = c.Mul(10, 5); Assert.AreEqual(expected, actual); }
public void TestDiv() { ICalc c = new Cal(); int expected = 2; int actual = c.Div(10, 5); Assert.AreEqual(expected, actual); }
private static bool parseDate2(ref Context ctx, Cal calen, bool second) { int day = -1; int mon = -1; int year = -1; day = ctx.getInt(); if (ctx.LookAhead(1).type == TokType.SYMB || ctx.LookAhead(1).type == TokType.UNK) // TODO unknown as symb? e.g. "15+Nov-1998"? { ctx.Consume(); } // day mon year OR year GEDDate.Types newType; if (ctx.LookAhead(1).type == TokType.WORD) { // day mon year ctx.Consume(); if (!getMonth(ctx.getString(), calen, ref mon)) { // TODO "15-Dep-1898" would ideally be parsed as "1898" but is not // Not a known month - might be a second keyword; assume YEAR year = day; day = -1; mon = -1; newType = GEDDate.Types.Range; } else { Token tok = ctx.Consume(); if (tok.type == TokType.SYMB) { tok = ctx.Consume(); } if (tok.type != TokType.NUM) { return(false); // Not a year, invalid } year = ctx.getInt(); ctx.Consume(); newType = GEDDate.Types.Exact; } } else { year = ctx.getInt(); day = -1; ctx.Consume(); newType = GEDDate.Types.Range; } ctx.Set(day, mon, year, newType, second); return(true); }
private void UpdateSession(Cal c) { string str = ""; if (HttpContext.Session["RecentCal"] != null) { str = (string)Session["RecentCal"]; } Session["RecentCal"] = str + c.Input1 + "+" + c.Input2 + "=" + c.Result + " "; }
static void Main(string[] args) { Cal c = new Cal(); //c.AddNunber(3, 6); int ca = c.AddNumber(3, 6); Console.WriteLine(ca); Console.WriteLine("Hello Guys!"); string x = Console.ReadLine(); Console.WriteLine(x); }
protected void btnCal_Click(object sender, EventArgs e) { Cal cal = new Cal(); int inputAge = 0; Cal.YearFormat inputFormat = (Cal.YearFormat)Enum.Parse(typeof(Cal.YearFormat), ddlYearFormat.SelectedValue, false); int.TryParse(txtAge.Text, out inputAge); if (inputAge > 0) { lblYear.Text = cal.GetBirthYear(inputAge, inputFormat).ToString(); } }
public void MulCal_ShouldAddTwoNumbers() { //Arrange int a = 2; int b = 5; //Act var result = Cal.MultiCal(a, b); //Assert Assert.AreEqual(10, result); }
static void Main(string[] args) { Demo d = delegate() { Console.WriteLine("Anonymous Method"); }; d(); Cal c = delegate(int a, int b) { return(a + b); }; Console.WriteLine(c(10, 20)); }
static void Main(string[] args) { char[] replace = { ' ', ',', '\t', '\n' }; string[] Silines = File.ReadAllLines("Si_new.txt", Encoding.Default); string[] SiO2lines = File.ReadAllLines("SiO2_new.txt", Encoding.Default); string[] SiO2_1000_nm_lines = File.ReadAllLines("SiO2_1000nm_on_Si_new_alpha_beta.dat", Encoding.Default); int Si_nm_linesNum = Silines.Length; int SiO2_nm_linesNum = SiO2lines.Length; int SiO2_1000_nm_linesNum = 0; List <Si_new_Data> Sirecords = new List <Si_new_Data>(); List <SiO2_new_Data> SiO2records = new List <SiO2_new_Data>(); List <SiO2_1000nm_Data> SiO2_1000_records = new List <SiO2_1000nm_Data>(); foreach (var line in Silines) { string[] splitData = line.Split(replace, StringSplitOptions.RemoveEmptyEntries); Sirecords.Add(new Si_new_Data { nm = splitData[0], n = splitData[1], k = splitData[2] }); } foreach (var line in SiO2lines) { string[] splitData = line.Split(replace, StringSplitOptions.RemoveEmptyEntries); SiO2records.Add(new SiO2_new_Data { nm = splitData[0], n = splitData[1], k = splitData[2] }); } foreach (var line in SiO2_1000_nm_lines) { string[] splitData = line.Split(replace, StringSplitOptions.RemoveEmptyEntries); SiO2_1000_records.Add(new SiO2_1000nm_Data { nm = splitData[0], AOI = splitData[1], alpha = splitData[2], beta = splitData[3] }); SiO2_1000_nm_linesNum++; } Cal.Cal_01(SiO2records, Sirecords, SiO2_1000_records, Si_nm_linesNum, SiO2_nm_linesNum, SiO2_1000_nm_linesNum); }
private static Cal CheckCalendar(Context ctx) { Token tok = ctx.LookAhead(); Cal calen = Cal.Greg; if (tok.type == TokType.CALEN) { if (!calLookup.TryGetValue(ctx.getString(), out calen)) { calen = Cal.Fut; } ctx.Consume(); } return(calen); }
public void Calc_檢查加法運算_負數加負數() { // arrange ICalc c = new Cal(); // 期望值 int expected = -5; //-2-3=-5 // act // 實際結果 int actual = c.Add(-2, -3); // assert // 比對(請注意類型) Assert.AreEqual(expected, actual); }
public void Calc_檢查加法運算() { // arrange ICalc c = new Cal(); // 期望值 int expected = 5; //2+3=5 // act // 實際結果 int actual = c.Add(2, 3); // assert // 比對(請注意類型) Assert.AreEqual(expected, actual); }
// TODO appears not to be thread safe: some tests fail under code coverage analysis with this enabled //private static DateTokens _dateTokenSingleton; //private static DateTokens Tokenizer //{ // get { return _dateTokenSingleton ?? (_dateTokenSingleton = new DateTokens()); } //} public static GEDDate DateParser(string datestr) { DateTokens tok = new DateTokens(); Context ctx = new Context(datestr, tok.Tokenize(datestr)); // TODO this is not standard, but some programs do this Cal calen = CheckCalendar(ctx); if (calen != Cal.Greg) // TODO other calendar support { return(new GEDDate(GEDDate.Types.Unknown)); } KeyW initKeyword = CheckInitialKeyword(ctx); ctx.gd = new GEDDate(); if (!parseDate(ref ctx, calen, second: false)) { return(ctx.gd); } // check for an era Era era = CheckEra(ctx); ctx.SetBC(era == Era.BC); KeyW secondKeyword = CheckSecondKeyword(ctx); if (secondKeyword != KeyW.None) { ctx.gd2 = new GEDDate(); // expecting a second date if (!parseDate(ref ctx, calen, second: true)) { return(new GEDDate(GEDDate.Types.Unknown)); // TODO track/note issues } Era era2 = CheckEra(ctx); ctx.SetBC(era2 == Era.BC, second: true); } // Still have unparsed stuff - must be problem if (ctx.LookAhead().type != TokType.EOF) { return(new GEDDate(GEDDate.Types.Unknown)); // TODO track/note issues } MakeJulianDayRange(ctx, initKeyword, secondKeyword); return(ctx.gd); }
public static IAirfoilCoordinate Lerp(IAirfoilCoordinate A, IAirfoilCoordinate B, double rate) { if (A.N != B.N) { B.N = A.N; } var result = new SeligCoordinate(); for (int i = 0; i < A.N; i++) { result.Points.Add(new Pos(A.NormalPoints[i].x, Cal.Lerp(A.NormalPoints[i].y, B.NormalPoints[i].y, rate))); } return((IAirfoilCoordinate)result); }
private static bool parseSymAndDate(ref Context ctx, Cal calen, bool second = false) { // e.g. "~1798" Token tok = ctx.LookAhead(); if (ctx.getString() == "~") { ctx.Consume(); if (parseDate2(ref ctx, calen, second)) { ctx.SetType(GEDDate.Types.Estimated); return(true); } } return(false); }
public override bool OpenClient () { if (!this.source.IsLocal ()) { Logger.Log.Debug ("Skipping remote calendar {0}", this.source.Uri); return false; } try { this.cal = new Cal (this.source, cal_source_type); this.cal.Open (true); } catch (Exception e) { Logger.Log.Warn (e, "Unable to open calendar {0}:", this.source.Uri); return false; } return true; }
public void Calc_檢查乘法運算_乘以零() { ICalc c = new Cal(); // arrange //Cal c = new Cal(); //注入測試目標 // 期望值 int expected = 0; //2*0=0 // act // 實際結果 int actual = c.Mul(2, 0); // assert // 比對(請注意類型) Assert.AreEqual(expected, actual); }
public void Calc_檢查減法運算() { ICalc c = new Cal(); // arrange //Cal c = new Cal(); //注入測試目標 // 期望值 int expected = -1; //2-3=-1 // act // 實際結果 int actual = c.Sub(2, 3); // assert // 比對(請注意類型) Assert.AreEqual(expected, actual); }
public void Calc_檢查除法運算_除以零() { ICalc c = new Cal(); // arrange //Cal c = new Cal(); //注入測試目標 // 期望值 int expected = 0; //10/0=0 // act // 實際結果 int actual = c.Div(10, 0); // assert // 比對(請注意類型) Assert.AreEqual(expected, actual); }
public void Test_getForce() { cal = new Cal(); cal.setForce(90); Assert.AreEqual(90, cal.getForce()); }
private void AddCategory(Evolution.Source source) { Logger.Debug ("AddCategory"); EDSCategory edsCategory; Gtk.TreeIter iter; if (source.IsLocal()) { Cal taskList = new Cal (source, CalSourceType.Todo); edsCategory = new EDSCategory (source, taskList); iter = categoryListStore.Append (); categoryListStore.SetValue (iter, 0, edsCategory); //Assumption : EDS Creates atleast one System category. if (edsCategory.IsSystem) this.defaultCategory = edsCategory; if (!taskList.Open (true)) { Logger.Debug ("laskList Open failed"); return; } CalView query = taskList.GetCalView ("#t"); if (query == null) { Logger.Debug ("Query object creation failed"); return; } else query.Start (); query.ObjectsModified += TasksModified; query.ObjectsAdded += TasksAdded; query.ObjectsRemoved += TasksRemoved; } }
public void test_getAcceleration() { cal = new Cal(); cal.setAcceleration(88); Assert.AreEqual(88, cal.getAcceleration()); }