public void ReductionWorks(int iterations, double maxIncrementsPerIteration) { var incrementer = new Incrementer(); for (int i = 0; i < iterations; i++) { incrementer.AddIncrements(Brandom.Gen.NextDouble() * maxIncrementsPerIteration); } var exactBeforeReduction = incrementer.ExactIncrements; var fullBeforeReduction = incrementer.FullIncrements; var partialBeforeReduction = incrementer.PartialIncrements; Assert.That(exactBeforeReduction - fullBeforeReduction, Is.EqualTo(partialBeforeReduction), $"Before {nameof(incrementer.Reduce)}: {nameof(incrementer.ExactIncrements)} - {nameof(incrementer.FullIncrements)} == {nameof(incrementer.PartialIncrements)}"); var reductionAmount = incrementer.Reduce(); AssertAll.Of( $"After calling {nameof(incrementer.Reduce)}", () => Assert.That(reductionAmount, Is.EqualTo(fullBeforeReduction), $"{nameof(incrementer.Reduce)} should have returned the previous {nameof(incrementer.FullIncrements)}"), () => Assert.That(incrementer.ExactIncrements, Is.EqualTo(partialBeforeReduction), $"{nameof(incrementer.ExactIncrements)} should equal the previous {nameof(incrementer.PartialIncrements)}"), () => Assert.That(incrementer.ExactIncrements, Is.Positive.And.LessThan(1), $"1 > {nameof(incrementer.ExactIncrements)} >= 0") ); }
public void _01() { var incrementer = new Incrementer(); incrementer.CountedADozen += (_, incrementerEventArgs) => { testOutputHelper.WriteLine(incrementerEventArgs.IterationCount.ToString()); }; incrementer.DoCount(); }
public void _01() { var incrementer = new Incrementer(); var dozens = new Dozens(incrementer); incrementer.DoCount(); Assert.Equal(9, dozens.DozensCount); }
static void Main(string[] args) { Incrementer incrementer = new Incrementer(); Dozens dozenCounter = new Dozens(incrementer); incrementer.DoCount(); Console.WriteLine("number of dozen = {0}", dozenCounter.DozenCount); }
static void Main() { var incrementer = new Incrementer(); Dozens dozensCounter = new Dozens(incrementer); incrementer.DoCount(); Console.WriteLine(dozensCounter.DozensCount); }
static void Main() { Incrementer incrementer = new Incrementer(); Dozens dozensCounter = new Dozens(incrementer); incrementer.DoCount(); Console.WriteLine("Number of dozens = {0}", dozensCounter.DozensCount); }
static void Main(string[] args) { Incrementer incrementer = new Incrementer(); // สร้าง publisher Dozens dozenCounter = new Dozens(incrementer); // สร้าง subscriber โดยระบุ publisher เป็น parameter incrementer.DoCount(); // จำลองสถานการณ์ที่ firing event Console.WriteLine("number of dozen = {0}", dozenCounter.DozenCount); // รายงานสรุป }
public void ZeroPeriod() { var incrementer = new Incrementer() { Period = TimeSpan.Zero }; Assert.That(incrementer, Has.Property(nameof(incrementer.Hertz)).EqualTo(double.PositiveInfinity)); }
public void Visit(Incrementer n) { Helpers.Write($"{n.IdentifierName}{n.Operator}"); if (n.IncrementExpression != null) { Helpers.Write(" "); n.IncrementExpression.Accept(this); } }
public void ZeroHertz() { var incrementer = new Incrementer() { Hertz = 0 }; Assert.That(incrementer, Has.Property(nameof(incrementer.Period)).Null); }
static void Main() { Incrementer incrementer = new Incrementer(); // instantiate Publisher Dozens dozensCounter = new Dozens(incrementer); // instantiate Subscriber incrementer.DoCount(); // invoke method in Publisher, which will raise event. Console.WriteLine("Number of dozens = {0}", dozensCounter.DozensCount); Console.ReadLine(); }
public void demo3() { Incrementer incrementer = new Incrementer(); //Dozens dozensCounter = new Dozens(incrementer); Dozens dozensCounter = new Dozens(); incrementer.CoutedADozen += dozensCounter.IncrementDozensCount; incrementer.DoCount(); Console.WriteLine("dozensCount:{0}", dozensCounter.DozensCount); }
public override AstNode Clone() { return(new ForNode( (Context == null ? null : Context.Clone()), Parser, (Initializer == null ? null : Initializer.Clone()), (Condition == null ? null : Condition.Clone()), (Incrementer == null ? null : Incrementer.Clone()), (Body == null ? null : Body.Clone()) )); }
public static void Main() { Incrementer i1 = new Incrementer(0); i1.Increment(1); i1.Increment(2); i1.Increment(3); i1.Increment(4); i1.Increment(5); i1.Increment(6); // will throw an ArgumentException } // end Main() method
public static void Main() { Incrementer i1 = new Incrementer(0); i1.Increment(1); i1.Increment(2); i1.Increment(3); i1.Increment(4); i1.Increment(5); i1.Increment(6); // throws an assertion exception } // end Main() method
public void ComputeElapsedIncrements(double periodInSeconds, double elapsedTimeInSeconds, double expectedIntervalAmount) { var incrementer = new Incrementer() { Period = TimeSpan.FromSeconds(periodInSeconds) }; var elapsedTime = TimeSpan.FromSeconds(elapsedTimeInSeconds); Assert.That(incrementer.ComputeElapsedIncrements(elapsedTime), Is.EqualTo(expectedIntervalAmount)); }
public void FromInvocation_should_allow_creating_mutable_parameter() { var descriptor = ParameterDescriptor.FromInvocation(ParameterInfoHelper.IntParameterInfo, i => ((Incrementer)i).GetNext()); Assert.That(descriptor.IsConstant, Is.False); Assert.That(descriptor.ParameterInfo, Is.SameAs(ParameterInfoHelper.IntParameterInfo)); Assert.That(descriptor.RawName, Is.EqualTo(ParameterInfoHelper.IntParameterInfo.Name)); Assert.That(descriptor.ValueEvaluator, Is.Not.Null); var incrementer = new Incrementer(); Assert.That(descriptor.ValueEvaluator(incrementer), Is.EqualTo(1)); Assert.That(descriptor.ValueEvaluator(incrementer), Is.EqualTo(2)); }
public void SetHertzGetPeriod(double setHertz, double expectedPeriodInSeconds) { var incrementer = new Incrementer() { Hertz = setHertz }; AssertAll.Of( $"After setting {nameof(incrementer.Hertz)}", incrementer, Has.Property(nameof(incrementer.Hertz)).EqualTo(setHertz), Has.Property(nameof(incrementer.Period)).EqualTo(TimeSpan.FromSeconds(expectedPeriodInSeconds)) ); }
public void AddTime(double periodInSeconds, double elapsedTimeInSeconds) { var incrementer = new Incrementer() { Period = TimeSpan.FromSeconds(periodInSeconds) }; incrementer.AddSeconds(elapsedTimeInSeconds); AssertAll.Of( incrementer, Has.Property(nameof(incrementer.Period)).Approximately(TimeSpan.FromSeconds(periodInSeconds)), Has.Property(nameof(incrementer.ExactIncrements)).CloseTo(elapsedTimeInSeconds / periodInSeconds) ); }
public static void Main() { Incrementer i1 = new Incrementer(0); Incrementer i2 = new DerivedIncrementer(20); i1.Increment(1); i1.Increment(2); i1.Increment(3); i1.Increment(4); i1.Increment(5); Console.WriteLine("-----------------------------"); i2.Increment(4); i2.Increment(5); i2.Increment(6); // will cause an assertion error } // end Main() method
public void SetPeriodGetHertz(double setPeriodInSeconds, double expectedHertz) { var period = TimeSpan.FromSeconds(setPeriodInSeconds); var incrementer = new Incrementer() { Period = period }; AssertAll.Of( $"After setting {nameof(incrementer.Period)}", incrementer, Has.Property(nameof(incrementer.Period)).EqualTo(period), Has.Property(nameof(incrementer.Hertz)).EqualTo(expectedHertz) ); }
public ActionResult Index(int id) { Incrementer inc = db.Incrementers.Find(id); if (inc.Count < 10) { inc.Count++; } if (ModelState.IsValid) { db.Entry(inc).State = EntityState.Modified; db.SaveChanges(); } return(View(db.Incrementers.Single())); }
public override void LoadEntity(ContainerBuilder builder, Process process, Entity entity) { //master updater builder.Register<IUpdate>((ctx) => { var context = new PipelineContext(ctx.Resolve<IPipelineLogger>(), process, entity); var incrementer = new Incrementer(context); var output = new OutputContext(context, incrementer); switch (output.Connection.Provider) { case "sqlserver": context.Debug("Registering {0} master updater", output.Connection.Provider); return new SqlMasterUpdater(output); default: context.Warn("Registering null updater"); return new NullMasterUpdater(); } }).Named<IUpdate>(entity.Key); }
public SemanticAtom Visit(Incrementer n) { var identifierType = CurrentBlock.LookupIdentifierType(n.IdentifierName, n.Location); var incrementExpressionType = n.IncrementExpression?.RealizedType; if (identifierType != Primitive.Int) { Globals.Errors.Add($"[{n.Location.StartLine}, {n.Location.StartColumn}] {n.IdentifierName} ({identifierType.Name}) is not assignable to {Primitive.Int.Name}, which is required for incrementing."); } if (incrementExpressionType != Primitive.Int && incrementExpressionType != null) { Globals.Errors.Add($"[{n.Location.StartLine}, {n.Location.StartColumn}] Source expression ({incrementExpressionType.Name}) is not assignable to {Primitive.Int.Name}."); } return(Primitive.Int); }
public void Visit(Incrementer n) { Helpers.WriteLine($"{_tab}{n.Text} [{n.Location.StartLine}, {n.Location.StartColumn}]"); Tab(); Helpers.WriteLine($"{_tab}Identifier: {n.IdentifierName}"); Helpers.WriteLine($"{_tab}Operation: {n.Operator}"); if (n.IncrementExpression != null) { Helpers.WriteLine("IncrementExpression"); Tab(); n.IncrementExpression.Accept(this); Untab(); Untab(); } }
public override void LoadEntity(ContainerBuilder builder, Process process, Entity entity) { builder.Register <IWrite>((ctx) => { var context = new PipelineContext(ctx.Resolve <IPipelineLogger>(), process, entity); var incrementer = new Incrementer(context); var output = new OutputContext(context, incrementer); switch (output.Connection.Provider) { case "sqlserver": context.Debug("Registering Sql Server writer"); return(new SqlEntityBulkInserter(output)); default: context.Warn("Registering null writer", output.Connection.Provider); return(new NullWriter(context)); } }).Named <IWrite>(entity.Key); }
static void Main(string[] args) { Console.WriteLine("This program will print Hello World 5 times."); Incrementer inc = new Incrementer(); MyClass myClass = new MyClass(); int totalWrites = 0; for (int i = 1; i <= 5; inc.IncrementInteger(i)) { Console.WriteLine("Hello World!"); if (++totalWrites > 5) { Console.WriteLine("Too many!"); break; } } Console.ReadLine(); }
public static async Task <ICollection <SourceDirectory> > ScanMachine(CancellationToken cancellationToken, ProgressViewModel progress) { var drives = await Task.Run(() => DriveInfo.GetDrives() .Where(d => d.DriveType == DriveType.Fixed && d.IsReady && d.TotalSize > 53687091200)//only drives bigger than 50 GB which are fixed and ready .Select(d => d.RootDirectory)); var timer = new Stopwatch(); timer.Start(); HashSet <string> skipList = await Task.Run(() => BuildSkipList()); var inc = new Incrementer(progress); var buildStrategyDirs = await Task.Run(() => drives.AsParallel().Select(d => GetAllBuildStrategiesDirectories(d, skipList, inc, cancellationToken)).SelectMany(r => r)); var environments = await Task.Run(() => buildStrategyDirs.Select(r => IdentifyEnvironment(r)).Where(e => e != null).ToList()); timer.Stop(); log.InfoFormat("Searching for environments took {0:0.0} seconds, found {1} source directories.", timer.Elapsed.TotalSeconds, environments.Count); return(environments); }
public static void Main() { Incrementer i1 = new Incrementer(0); Incrementer i2 = new DerivedIncrementer(20); Incrementer i3 = new WeakenedDerivedIncrementer(10); Incrementer i4 = new StrengthenedDerivedIncrementer(10); i1.Increment(1); i1.Increment(2); i1.Increment(3); i1.Increment(4); i1.Increment(5); Console.WriteLine("-----------------------------"); i2.Increment(4); i2.Increment(5); Console.WriteLine("-----------------------------"); i3.Increment(5); Console.WriteLine("-----------------------------"); i4.Increment(2); // OK so far... i4.Increment(3); // OK here too... i4.Increment(4); // Wait a minute...this should work! } // end Main() method
public override string ToCode(ToCodeFormat format) { StringBuilder sb = new StringBuilder(); sb.Append("for("); if (Initializer != null) { sb.Append(Initializer.ToCode()); } sb.Append(';'); CodeSettings codeSettings = Parser.Settings; if (codeSettings.OutputMode == OutputMode.MultipleLines && codeSettings.IndentSize > 0) { sb.Append(' '); } if (Condition != null) { sb.Append(Condition.ToCode()); } sb.Append(';'); if (codeSettings.OutputMode == OutputMode.MultipleLines && codeSettings.IndentSize > 0) { sb.Append(' '); } if (Incrementer != null) { sb.Append(Incrementer.ToCode()); } sb.Append(')'); string bodyString = ( Body == null ? string.Empty : Body.ToCode() ); sb.Append(bodyString); return(sb.ToString()); }
public static void Main() { Incrementer i1 = new Incrementer(0); Incrementer i2 = new DerivedIncrementer(20); Incrementer i3 = new WeakenedDerivedIncrementer(10); i1.Increment(1); i1.Increment(2); i1.Increment(3); i1.Increment(4); i1.Increment(5); Console.WriteLine("-----------------------------"); i2.Increment(4); i2.Increment(5); Console.WriteLine("-----------------------------"); i3.Increment(5); i3.Increment(6); // it does not cause an error here... i3.Increment(7); // nor here i3.Increment(8); // nor here i3.Increment(9); // nor here i3.Increment(10); // nor here i3.Increment(11); // ...but here it does! } // end Main() method
private bool FindMatch(GameState state, Coords input, Coords lastInput, Incrementer inc, IEnumerable<PatternElement> restOfPattern, out List<Coords> output) { if (restOfPattern.Count() == 0) { // Nothing more to match, make sure the last matched input // was the actual end of the input: output = new List<Coords>(); if (lastInput == null || Coords.Match(lastInput, input)) { return true; } else { return false; } } var currentPattern = restOfPattern.First(); var newRestOfPattern = restOfPattern.Skip(1); foreach (var count in currentPattern.Count) { // Try all combinations of the pattern count/range Coords currentInput = input; List<Coords> currentCapture = new List<Coords>(); for (int i = 0; i < count; i++) { // All elements must match if (currentPattern.Predicate(state, currentInput)) { currentCapture.Add(currentInput); currentInput = inc(currentInput); } else { goto tryDifferentCount; } } // Current round matches, try the rest List<Coords> newCapture; if (FindMatch(state, currentInput, lastInput, inc, newRestOfPattern, out newCapture)) { currentCapture.AddRange(newCapture); output = currentCapture; return true; } tryDifferentCount: { } } output = null; return false; }