Пример #1
0
        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);
        }
Пример #2
0
            public PeriodicallyScheduledWorkItem(TState state, TimeSpan period, Func <TState, TState> action)
            {
                _state  = state;
                _action = action;

                _cancel = Cal.StartPeriodicTimer(Tick, period);
            }
Пример #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Cal cal = new Cal();

            cal.Add(10, 20);
            MessageBox.Show(cal.Result.ToString());
        }
Пример #4
0
        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);
            }
        }
Пример #5
0
        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));
        }
Пример #6
0
        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);
        }
Пример #7
0
        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
            }
        }
Пример #8
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);
        }
Пример #9
0
        static void Main(string[] args)
        {
            ICalc c = new Cal();
            int   s = c.Add(2, 3);

            Console.WriteLine($"2+3={s}");
            Console.ReadKey();
        }
Пример #10
0
        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));
        }
Пример #11
0
        static void Main(string[] args)
        {
            Cal cal = new Cal();
            cal.setMass(90);
            Console.WriteLine(cal.getMass());

            // Suspend the console.
            Console.ReadKey();
        }
Пример #12
0
        static void Main21(string [] args)
        {
            Cal cal = new Cal();                            //인스턴스생성

            Console.WriteLine("x + y = " + cal.Plus(4, 5)); //인스턴스 메서드 호출
            Console.WriteLine();
            cal.Print("홍길동");
            cal.Print();
        }
Пример #13
0
        public void TestAdd()
        {
            ICalc c = new Cal();

            int expected = 5;

            int actual = c.Add(2, 3);

            Assert.AreEqual(expected, actual);
        }
Пример #14
0
        public void TestSub()
        {
            ICalc c = new Cal();

            int expected = 0;

            int actual = c.Sub(-5, -5);

            Assert.AreEqual(expected, actual);
        }
Пример #15
0
        public void TestMul()
        {
            ICalc c = new Cal();

            int expected = 50;

            int actual = c.Mul(10, 5);

            Assert.AreEqual(expected, actual);
        }
Пример #16
0
        public void TestDiv()
        {
            ICalc c = new Cal();

            int expected = 2;

            int actual = c.Div(10, 5);

            Assert.AreEqual(expected, actual);
        }
Пример #17
0
        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);
        }
Пример #18
0
        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 + "    ";
        }
Пример #19
0
        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();
            }
        }
Пример #21
0
        public void MulCal_ShouldAddTwoNumbers()
        {
            //Arrange
            int a = 2;
            int b = 5;

            //Act
            var result = Cal.MultiCal(a, b);

            //Assert
            Assert.AreEqual(10, result);
        }
Пример #22
0
        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));
        }
Пример #23
0
        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);
        }
Пример #24
0
        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);
        }
Пример #25
0
        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);
        }
Пример #26
0
        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);
        }
Пример #27
0
        // 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);
        }
Пример #28
0
        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);
        }
Пример #29
0
        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);
        }
Пример #30
0
		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;
		}
Пример #31
0
        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);
        }
Пример #32
0
        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);
        }
Пример #33
0
        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);
        }
Пример #34
0
 public void Test_getForce()
 {
     cal = new Cal();
     cal.setForce(90);
     Assert.AreEqual(90, cal.getForce());
 }
Пример #35
0
        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;
               }
        }
Пример #36
0
 public void test_getAcceleration()
 {
     cal = new Cal();
     cal.setAcceleration(88);
     Assert.AreEqual(88, cal.getAcceleration());
 }