private IEnumerator RunAction(Action action) { action.isRunning = false; float waitTime = action.Run(); if (waitTime > 0f) { while (action.isRunning) { yield return(new WaitForSeconds(waitTime)); waitTime = action.Run(); } } int actionEnd = action.End(); if (actionEnd != 0) { nextActionNumber = actionEnd; } // Fix bug where actionlist would continue even if game is paused while (stateHandler.gameState == GameState.Paused) { yield return(new WaitForFixedUpdate()); } ProcessAction(nextActionNumber); }
public void TestInvoiceProgram() { #if !DEBUG Assert.Multiple(() => { #endif Action app = InvoiceTest.Main; string actual = app.Run( "001234", // initial part number "Hammer", // initial part description 451, // quantity 1.79m, // price per item "ABCDEF", // updated part number "Golf Ball", // updated part description, 98, // updated quantity, 3.21m // updated price per item ); actual.Assert( ExpectTo.AssertContinuously | ExpectTo.Contain, "001234", // initial part number "Hammer", // initial part descritpion "451", // initial quantity "1.79", // initial price per item "807.29", // initial invoice amount "ABCDEF", // updated part number "Golf Ball", // updated description "98", // updated quantity "3.21", // updated price per item "314.58" // updated invoice amount ); actual = app.Run( "001234", // initial part number "Hammer", // initial part description 451, // quantity 1.79m, // price per item "001234", // updated part number "Hammer", // updated part description, -1, // updated quantity, -0.5m // updated price per item ); actual.Assert( ExpectTo.AssertContinuously | ExpectTo.Contain, "001234", // initial part number "Hammer", // initial part descritpion "451", // initial quantity "1.79", // initial price per item "807.29", // initial invoice amount "001234", // updated part number "Hammer", // updated description "451", // updated quantity with a negative value "1.79", // updated price per item with a negative value "807.29" // updated invoice amount overall ); #if !DEBUG }); #endif }
public void TestOddNumbers() { Action app = new Action(OddNumbers.Main); app.Run(5, 10).Assert(5, 7, 9); app.Run(6, 11).Assert(7, 9, 11); app.Run(6, 12).Assert(7, 9, 11); app.Run(-5, 0).Assert(-5, -3, -1); app.Run(-5, 7).Assert(-5, -3, -1, 1, 3, 5, 7); }
/// <inheritdoc /> protected override async Task <Result <Unit, IError> > Run( IStateMonad stateMonad, CancellationToken cancellationToken) { var elements = await Array.Run(stateMonad, cancellationToken); if (elements.IsFailure) { return(elements.ConvertFailure <Unit>()); } var currentState = stateMonad.GetState().ToImmutableDictionary(); async ValueTask <Result <Unit, IError> > Apply(T element, CancellationToken cancellation) { var scopedMonad = new ScopedStateMonad( stateMonad, currentState, new KeyValuePair <VariableName, object>(Variable, element !) ); var result = await Action.Run(scopedMonad, cancellation); return(result); } var finalResult = await elements.Value.ForEach(Apply, cancellationToken); return(finalResult); }
/// <inheritdoc /> protected override async Task <Result <Unit, IError> > Run( IStateMonad stateMonad, CancellationToken cancellationToken) { while (true) { var conditionResult = await Condition.Run(stateMonad, cancellationToken); if (conditionResult.IsFailure) { return(conditionResult.ConvertFailure <Unit>()); } if (conditionResult.Value) { var actionResult = await Action.Run(stateMonad, cancellationToken); if (actionResult.IsFailure) { return(actionResult.ConvertFailure <Unit>()); } } else { break; } } return(Unit.Default); }
private void OnTimerCallback(object state) { //if (ChoGuard.IsDisposed(this)) // return; Pause(); try { if (_timerServiceCallback != null) { _timerServiceCallback.Run((T)state, _timeout); } //new Action<T>(OnTimerServiceCallback).WaitFor((T)state, _timeout); } catch (TimeoutException ex) { if (!_silent) { throw new ChoTimerServiceException(String.Format("{1}: Timeout [{0} ms] elapsed prior to completion of the method.", _timeout, _name), ex); } else { ChoProfile.GetContext(Name).AppendIf(ChoTrace.ChoSwitch.TraceError, String.Format("Timeout [{0} ms] elapsed prior to completion of the method.", _timeout)); } } //if (ChoGuard.IsDisposed(this)) // return; Continue(); }
private void TryToTakeAction(MLAction action) { if (IsPerformingMove()) { return; } if (isAnim) { return; } if (MLActionFactory.IsPunch(action)) { if (punchAction.IsOnCooldown()) { return; } punchAction.Run(action == MLAction.PUNCH_LEFT ? Direction.LEFT : Direction.RIGHT); } if (MLActionFactory.IsDodge(action)) { if (dodgeAction.IsOnCooldown()) { return; } dodgeAction.Run(action == MLAction.DODGE_LEFT ? Direction.LEFT : Direction.RIGHT); } }
private void OnTimerCallback(object state) { if (_isStopped || _isPaused) { _resumeEvent.WaitOne(); } try { if (_timerServiceCallback != null) { _timerServiceCallback.Run((T)state, _timeout); } //new Action<T>(OnTimerServiceCallback).WaitFor((T)state, _timeout); } catch (TimeoutException ex) { if (!_silent) { throw new ChoTimerServiceException(String.Format("{1}: Timeout [{0} ms] elapsed prior to completion of the method.", _timeout, _name), ex); } else { ChoTrace.Error(String.Format("Timeout [{0} ms] elapsed prior to completion of the method.", _timeout)); } } Thread.Sleep(_period); }
public void TestAccountDepositWithdraw() { #if !DEBUG Assert.Multiple(() => { #endif var accountClass = new TypeAssert<Account>(); dynamic account = accountClass.New("John Smith", 20m); Assert.AreEqual(20m, account.Balance, "Initial balance"); account.Deposit(15.5m); Assert.AreEqual(35.5m, account.Balance, "20 + 15.5"); account = accountClass.New("John Smith", 20m); account.Withdraw(15.5m); Assert.AreEqual(4.5m, account.Balance, "20 - 15.5"); account = accountClass.New("John Smith", 20m); account.Deposit(-0.5m); Assert.AreEqual(20m, account.Balance, "cannot deposit negative amount."); account = accountClass.New("John Smith", 20m); Action tester = () => { account.Withdraw(25m); }; string output = tester.Run(); Assert.AreEqual(20m, account.Balance, "cannot deposit negative amount."); output.Assert("Withdrawal amount exceeded account balance."); #if !DEBUG }); #endif }
public void TestAccountProgram() { #if !DEBUG Assert.Multiple(() => { #endif Action app = AccountTest.Main; var actual = app.Run( "Jane Green", 123.45m, // account1 "John Blue", 54.32m, // account2 -0.04m, // account1 deposit 76.4m, // account2 deposit 121.44m, // account1 withdraw 135m // account2 withdraw ); actual.Assert( ExpectTo.AssertContinuously | ExpectTo.Match, @"Jane Green.*?123\.45", // amount1's initial balance @"John Blue.*?54\.32", // amount2's initial balance @"Jane Green.*?123\.45", // amount1's deposit @"John Blue.*?130\.72", // amount2's deposit @"Jane Green.*?2\.01", // amount1's withdraw @"Withdrawal amount exceeded account balance", // amount2's withdrawl error message @"John Blue.*130\.72" // amount2's withdraw ); #if !DEBUG }); #endif }
/// <summary> /// Handles a <see cref="System.Windows.Forms.Control.Click"/> event raised by the control. /// Executes the action method <see cref="Action.Run()"/>. /// </summary> /// <param name="sender">not used</param> /// <param name="e">not used</param> void RunAction(object sender, EventArgs e) { if (logger.IsDebugEnabled) { logger.Debug(string.Format("Control '{0}' has been clicked. Running corresponding action.", action.Name)); } action.Run(); }
// Use this for initialization void Start() { Sequence q = new Sequence(new UIFadeTo(0.8f, 0.5f), new UIFadeTo(0.5f, 1.0f)); Action.Run(textTest, new RepeatForever(q)); //Actor anActor = Actor.GetActor(textTest); //anActor.UIFadeOut(1.0f); }
/// <summary> /// Run the script /// </summary> /// <returns>True on success</returns> public virtual bool Run() { if (Action != null) { return(Action.Run()); } return(false); }
/// <summary> /// Append the C# codes to the string builder for easy-to-build assertions. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sb"></param> /// <param name="action"></param> /// <param name="inputs"></param> public static void Append <T>(this StringBuilder sb, Action action, T[] inputs) { string inputString = inputs.ToCode().Trim('{', '}'); sb.AppendLine($"actual = app.Run({inputString});"); var output = action.Run(inputs); string outputString = output.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToCode().Trim('{', '}'); sb.AppendLine($"actual.Assert({outputString});"); }
private ActionResult RunActionAndRedirect(Action action, AuthorisedAction auth = null) { // Log/save the action to the database before running... action.StoreRecord(); DbContext.SaveChanges(); // Run the action if (auth != null) { action.Run(auth.User); auth.IsUsed = true; } else { action.Run((Framework.Core.Entities.User)User); } // Redirect... return(HandleRedirect(action, auth, GetReturnUrl())); }
public Action RunNext(GameState gameState) { if (this.actions.Count == 0) { return(null); } Action nextAction = actions.Dequeue(); nextAction.Run(gameState); return(nextAction); }
public void TestParkClassMethods() { #if !DEBUG Assert.Multiple(() => { #endif var park = new TypeAssert<Park>(); Park[] parks = new Park[] { park.New( "Park 1", "123 Test Drive", (FacilityType)Enum.Parse(typeof(FacilityType), "National"), "444-432-9876", 5, 11, 4.56m), park.New( "Park 2", "1 Park Street", (FacilityType)Enum.Parse(typeof(FacilityType), "Local"), "777-888-3332", 13, 18, 7.89m), park.New( "Park 3", "1 Midnight Lane", (FacilityType)Enum.Parse(typeof(FacilityType), "State"), "893-221-1234", 0, 12, 12.34m) }; var show = park.Method( "Show", BindingFlags.Public | BindingFlags.Static, new Param<Park[]>("parks") ); var calculate = park.Method<decimal>( "CalculateFee", BindingFlags.Public | BindingFlags.Static, new Param<int>("numberOfVisitors"), new Param<Park[]>("parks") ); // Park.Show(parks); Action call = () => show.Invoke(null, new object[] { parks }); string actual = call.Run(); actual.Assert( "Park 1 National Park 5 AM to 11 AM $4.56 444-432-9876 123 Test Drive", "Park 2 Local Park 1 PM to 6 PM $7.89 777-888-3332 1 Park Street", "Park 3 State Park 12 AM to 12 PM $12.34 893-221-1234 1 Midnight Lane" ); // decimal actualFee = Park.CalculateFee(765, parks); decimal actualFee = (decimal)calculate.Invoke(null, new object[] { 765, parks }); Assert.AreEqual(18964.35m, actualFee); #if !DEBUG }); #endif }
private void Run(Operation operation, int index, T item) { Action action = new Action(this, operation, index, item); if (undoRedoManager.CanRun) { undoRedoManager.Run(action); } else { action.Run(null, ActionType.Do); } }
public int[] TestFibonacciNumbers(int lastNumber) { Action app = new Action(FibonacciNumbers.Main); string actual = app.Run(lastNumber); var matches = Regex.Matches(actual, @"([-]?\d+)", RegexOptions.RightToLeft | RegexOptions.Singleline); int[] actuals = new int[matches.Count]; for (int i = 0, j = matches.Count - 1; i < matches.Count; i++, j--) { Match match = matches[j]; actuals[i] = int.Parse(match.Groups[1].Value); } return(actuals); }
private void Deliver(Action action) { if (queue.Contains(action)) { return; } //Debug.Log("Deliver: " + action.name); if (running.Contains(action)) { running.Remove(action); } queue.Add(action); action.Queue(); action.Run(); }
private void Accept(Action action) { if (running.Contains(action)) { return; } // Debug.Log("Accept: " + action.name); if (queue.Contains(action)) { queue.Remove(action); } running.Add(action); action.Restart(); action.Run(); }
public static Worker Timeout(this Action action, int milliseconds) { var actionWorker = action.Run(); var cancelWorker = new Worker(actionWorker.Cancel); if (actionWorker.RegisterFinalizeAction(cancelWorker.Cancel)) { var t = new Timer(Worker.run, cancelWorker, milliseconds, -1); if (!cancelWorker.RegisterFinalizeAction(t.Dispose)) { t.Dispose(); } } return(actionWorker); }
IEnumerator ShowDemo() { Debug.Log(" exicuting sequence and with ease actions "); ResetMovingObject(); Sequence q2 = new Sequence(new EaseOut(new MoveBy(3, new Vector3(3, 1, 1)), 0.2f), new EaseExponentialInOut(new RotateBy(5, new Vector3(180, 0, 0))), new MoveBy(3, new Vector3(-3, 1, 1)), new EaseBounceIn(new RotateBy(3, new Vector3(0, 60, 0))) ); Action.Run(movingObject, new Repeat(q2, 2)); yield return(new WaitForSeconds(30)); yield return(StartCoroutine(anAnimation())); Debug.Log("Actor demo done. Now exicuting two actions parallely "); Action.Run(movingObject, new MoveBy(10, new Vector3(10, 1, 1))); Action.Run(movingObject, new RotateBy(5, new Vector3(180, 0, 0))); yield return(new WaitForSeconds(11)); Debug.Log(" Now exicuting sequence and repeat-2 actions "); ResetMovingObject(); Sequence q = new Sequence(new MoveBy(3, new Vector3(3, 1, 1)), new RotateBy(5, new Vector3(180, 0, 0)), new MoveBy(3, new Vector3(-3, 1, 1)), new RotateBy(3, new Vector3(0, 60, 0)) ); Action.Run(movingObject, new Repeat(q, 2)); yield return(new WaitForSeconds(30)); Debug.Log(" Now exicuting Spawn actions "); ResetMovingObject(); Action.Run(movingObject, new Spawn(new MoveBy(10, new Vector3(2, 1, 1)), new MoveBy(10, new Vector3(0, 3, 0)), new RotateBy(10, new Vector3(0, 180, 0)))); yield return(new WaitForSeconds(10)); Debug.Log(" All tests are completed "); }
/// <summary> /// Append the C# codes to the string builder for easy-to-build assertions; all the outputs will add new-lines for readability. /// </summary> /// <typeparam name="T"></typeparam> /// <param name="sb"></param> /// <param name="action"></param> /// <param name="inputs"></param> public static void AppendLine <T>(this StringBuilder sb, Action action, T[] inputs) { var comma = Utils.Comma; string inputString = inputs.ToCode().Trim('{', '}'); sb.AppendLine($"actual = app.Run({inputString});"); var output = action.Run(inputs); Utils.Comma = $",{Environment.NewLine}"; string outputString = output.Split(new[] { '\n', '\r' }, StringSplitOptions.RemoveEmptyEntries).ToCode().Trim('{', '}'); sb.AppendLine("actual.Assert("); sb.AppendLine($"{ outputString});"); Utils.Comma = comma; sb.AppendLine(); }
public void TestCompute() { #if !DEBUG Assert.Multiple(() => { #endif var assert = new TypeAssert<Shape>(); var compute = assert.Method( "Compute", BindingFlags.Static | BindingFlags.Public, new Param<Shape[]>("shapes") ); Shape[] shapes = new Shape[4]; // shapes[0] = new Circle(22, 88, 4); shapes[0] = (Shape)Activator.CreateInstance(typeof(Circle), 22, 88, 4); // shapes[1] = new Cube(79, 61, 8); shapes[1] = (Shape)Activator.CreateInstance(typeof(Cube), 79, 61, 8); // shapes[2] = new Sphere(8, 89, 2); shapes[2] = (Shape)Activator.CreateInstance(typeof(Sphere), 8, 89, 2); // shapes[3] = new Square(71, 96, 10); shapes[3] = (Shape)Activator.CreateInstance(typeof(Square), 71, 96, 10); // Shape.Compute(shapes); Action app = () => compute.Invoke(null, new[] { shapes }); string actual = app.Run(); actual.Assert( "Circle", "(22, 88) radius: 4", "50.26548246", "Cube", "(79, 61) side: 8", "384", "512", "Sphere", "(8, 89) radius: 2", "50.26548246", "33.51032164", "Square", "(71, 96) side: 10", "100" ); #if !DEBUG }); #endif }
public int TestAscendingFillers(params int[] input) { Action app = new Action(AscendingFillers.Main); string actual; actual = app.Run(input); var match = Regex.Match(actual, @"([-]?\d+)", RegexOptions.Singleline | RegexOptions.RightToLeft); if (match == null) { Assert.Fail($"The last number should indicate the sum of the fillers. - {actual}"); return(0); } int actualValue = int.Parse(match.Captures[0].Value); return(actualValue); }
public void TriggerAction(string actionTrigger, object[] parameters) { Action action = new Action(actionTrigger, parameters); action.Run(); //Debug.Log("SERVER - Resolving action: " + actionTrigger); // BUSCA AÇÃO // CHECA CONDIÇÕES // BUSCA ALVOS // EXECUTA EFEITO //string effect = actionTrigger; // temp //ActionEffectsManager.Instance.RunEffect(effect, game, parameters); }
public void TestEmployeeProgram() { #if !DEBUG Assert.Multiple(() => { #endif Action app = EmployeeTest.Main; string expected = app.Run(); expected.Assert( ExpectTo.AssertContinuously | ExpectTo.Match, "Bob.+?Jones.+?34[,]?500", // Initial Employee 1 "Susan.+?Baker.+?37[,]?809", // Initial Employee 2 "Bob.+?Jones.+?37[,]?950", // Employee 1 after 10% pay raise "Susan.+?Baker.+?41[,]?589\\.9" // Employee 2 after 10% pay raise ); #if !DEBUG }); #endif }
public void TestHomeShow() { #if !DEBUG Assert.Multiple(() => { #endif var home = new TypeAssert<Home>(); var show = home.Method( "Show", BindingFlags.Public | BindingFlags.Static, new Param<Home[]>("homes") { Params = true } ); var condo = new TypeAssert<Condo>(); var singleFamily = new TypeAssert<SingleFamily>(); dynamic condo1, condo2; dynamic[] homes = { singleFamily.New("Two Main Street", 1800, 100_000m), condo1 = condo.New("One Main Street", 1900, 100_000m, "A", 2000m, false), condo2 = condo.New("Three Main Street", 2000, 200_000m, "A", 1000m, true), singleFamily.New("Four Main Street", 2010, 300_000m) }; // Asserting: Home.Show(homes); Action showApp = () => show.Invoke(null, new object[] { homes.Cast<Home>().ToArray() }); var actual = showApp.Run(); actual.Assert( "Two Main Street 1800 $100,000.00", "One Main Street 1900 A $102,000.00", "One Main Street 1900 A $425.00", "Three Main Street 2000 A $201,000.00", "Three Main Street 2000 A $837.50", "Four Main Street 2010 $300,000.00" ); Assert.IsFalse(condo1.IsRental, "The rental option must be reverted"); Assert.IsTrue(condo2.IsRental, "The rental option must be reverted"); #if !DEBUG }); #endif }
static void Main(string[] args) { Action action = null; if (args != null && args.Length > 0) { args = args.Select(x => x.ToLower()).ToArray(); if (args[0] == "usstats") { action = () => UsStatProcessor.Run(); action.Run($"{nameof(UsStatProcessor)}.log"); } } var ex = new Exception("Invalid arguments", new Exception(string.Join(" ", args))); string message = $"[{DateTime.Now}] {ex.Message}: {ex.ToString()}\r\n"; var logFile = nameof(CoronaVirusUS) + ".log"; File.AppendAllText(logFile, message); return; }
IEnumerator PerformAction(Battler user, ActionType ActionType, Action action, int actionIndex, Battler target, IList<Battler> allCharacters, IList<Battler> allEnemies) { switch (ActionType) { case ActionType.Attack: yield return user.BattleBehavior.StandardAttack(user, target); break; case ActionType.Special: action.UseSP(user); yield return action.Run(user, target, allCharacters, allEnemies, this); break; case ActionType.Item: user.Inventory[actionIndex].RemoveFromInventory(user); user.Inventory[actionIndex].Use(user, target); break; case ActionType.Defend: Shield shield = Shields[user.BattlerIndex]; user.BattleBehavior.Defending = true; shield.StartCoroutine(shield.Enter()); break; } }
private void Accept(Action action) { if (running.Contains(action)) return; // Debug.Log("Accept: " + action.name); if (queue.Contains(action)) queue.Remove(action); running.Add(action); action.Restart(); action.Run(); }
private void Deliver(Action action) { if (queue.Contains(action)) return; //Debug.Log("Deliver: " + action.name); if (running.Contains(action)) running.Remove(action); queue.Add(action); action.Queue(); action.Run(); }
private IEnumerator RunAction (Action action) { if (useParameters) { action.AssignValues (parameters); } else { action.AssignValues (null); } if (isSkipping) { action.Skip (); } else { action.isRunning = false; float waitTime = action.Run (); if (action is ActionCheck || action is ActionCheckMultiple) { yield return new WaitForFixedUpdate (); } else if (waitTime > 0f) { while (action.isRunning) { if (this is RuntimeActionList && actionListType == ActionListType.PauseGameplay && !unfreezePauseMenus) { float endTime = Time.realtimeSinceStartup + waitTime; while (Time.realtimeSinceStartup < endTime) { yield return null; } } else { yield return new WaitForSeconds (waitTime); } waitTime = action.Run (); } } } EndAction (action); }
private IEnumerator RunAction(Action action) { if (useParameters) { action.AssignValues (parameters); } else { action.AssignValues (null); } if (isSkipping) { action.Skip (); } else { if (action is ActionRunActionList) { ActionRunActionList actionRunActionList = (ActionRunActionList) action; actionRunActionList.isSkippable = IsSkippable (); } action.isRunning = false; float waitTime = action.Run (); if (action is ActionParallel) {} else if (waitTime != 0f) { while (action.isRunning) { if (this is RuntimeActionList && actionListType == ActionListType.PauseGameplay && !unfreezePauseMenus) { float endTime = Time.realtimeSinceStartup + waitTime; while (Time.realtimeSinceStartup < endTime) { yield return null; } } else { yield return new WaitForSeconds (waitTime); } if (!action.isRunning) { // In rare cases (once an actionlist is reset) isRunning may be false but this while loop will still run ResetList (); break; } waitTime = action.Run (); } } } if (action is ActionParallel) { EndActionParallel ((ActionParallel) action); } else { EndAction (action); } }