/// <summary> /// Adds a new decimal value to the list of query parameters. /// </summary> /// <param name="key">The parameter name.</param> /// <param name="value">The parameter value.</param> /// <returns>The statement builder, for chaining method calls.</returns> public StatementBuilder AddValue(string key, decimal value) { NumberValue queryValue = new NumberValue(); queryValue.value = value.ToString(); return(AddValue(key, queryValue)); }
public void TestGetObjectNumberValue() { NumberValue numberValue = new NumberValue(); numberValue.value = "-1"; Assert.AreEqual("-1", PqlUtilities.GetValue(numberValue)); }
public void NumberValueShouldCastIntegerValue() { var func = new NumberValue(); var result = func.Execute(FunctionsHelper.CreateArgs("1000"), _parsingContext); Assert.AreEqual(1000d, result.Result); }
public override int GetHashCode() { int hash = 1; if (kindCase_ == KindOneofCase.NullValue) { hash ^= NullValue.GetHashCode(); } if (kindCase_ == KindOneofCase.NumberValue) { hash ^= NumberValue.GetHashCode(); } if (kindCase_ == KindOneofCase.StringValue) { hash ^= StringValue.GetHashCode(); } if (kindCase_ == KindOneofCase.BoolValue) { hash ^= BoolValue.GetHashCode(); } if (kindCase_ == KindOneofCase.StructValue) { hash ^= StructValue.GetHashCode(); } if (kindCase_ == KindOneofCase.ListValue) { hash ^= ListValue.GetHashCode(); } hash ^= (int)kindCase_; return(hash); }
public static SampleValue Mix(Symbol symbol, List <SampleValue> samples, Netlist netlist, Style style) { double sumVolume = 0.0; double sumTemperature = 0.0; bool needLna = false; foreach (SampleValue sample in samples) { sample.Consume(null, 0, null, netlist, style); sumVolume += sample.Volume(); sumTemperature += sample.Volume() * sample.Temperature(); needLna = needLna || sample.stateMap.state.lna; } NumberValue volume = new NumberValue(sumVolume); NumberValue temperature = new NumberValue(sumTemperature / sumVolume); SampleValue result = new SampleValue(symbol, new StateMap(symbol, new List <SpeciesValue> { }, new State(0, lna: needLna)), volume, temperature, produced: true); foreach (SampleValue sample in samples) { result.stateMap.Mix(sample.stateMap, volume.value, sample.Volume(), style); // mix adding the means and covariances, scaled by volume result.AddReports(sample.RelevantReports(style)); } return(result); }
public async Task ShouldEvaluateFilters(string source, string expected) { _parser.TryParse(source, out var template, out var error); var options = new TemplateOptions(); var context = new TemplateContext(options); options.Filters.AddFilter("inc", (i, args, ctx) => { var increment = 1; if (args.Count > 0) { increment = (int)args.At(0).ToNumberValue(); } return(NumberValue.Create(i.ToNumberValue() + increment)); }); options.Filters.AddFilter("append", (i, args, ctx) => { var s = i.ToStringValue(); for (var k = 0; k < args.Count; k++) { s += args.At(k).ToStringValue(); } return(new StringValue(s)); }); var result = await template.RenderAsync(context); Assert.Equal(expected, result); }
public override ValueTask <Completion> WriteToAsync(TextWriter writer, TextEncoder encoder, TemplateContext context) { context.IncrementSteps(); // We prefix the identifier to prevent collisions with variables. // Variable identifiers don't represent the same slots as inc/dec ones. // c.f. https://shopify.github.io/liquid/tags/variable/ var prefixedIdentifier = Prefix + Identifier; var value = context.GetValue(prefixedIdentifier); if (value.IsNil()) { value = NumberValue.Zero; } else { value = NumberValue.Create(value.ToNumberValue() + 1); } context.SetValue(prefixedIdentifier, value); value.WriteTo(writer, encoder, context.CultureInfo); return(Normal()); }
public async Task ShouldUseCurrentContext() { var e = new ForStatement( new List <Statement> { new AssignStatement("z", new LiteralExpression(NumberValue.Create(1))) }, "i", new RangeExpression( new LiteralExpression(NumberValue.Create(1)), new LiteralExpression(NumberValue.Create(3)) ), null, null, false ); var t = new TemplateContext(); t.SetValue("z", 0); Assert.Equal(0, t.GetValue("z").ToNumberValue()); var sw = new StringWriter(); await e.WriteToAsync(sw, HtmlEncoder.Default, t); Assert.Equal(1, t.GetValue("z").ToNumberValue()); }
public async Task ForEvaluatesMemberOptionsOffsetOnly() { var context = new TemplateContext() .SetValue("offset", 3) ; var e = new ForStatement( new List <Statement> { CreateMemberStatement("i") }, "i", new RangeExpression( new LiteralExpression(NumberValue.Create(1)), new LiteralExpression(NumberValue.Create(5)) ), null, new MemberExpression(new IdentifierSegment("offset")), true ); var sw = new StringWriter(); await e.WriteToAsync(sw, HtmlEncoder.Default, context); Assert.Equal("54", sw.ToString()); }
public override void ConfigureServices(IServiceCollection services) { services.Configure <TemplateOptions>(o => { o.Scope.SetValue("Site", new ObjectValue(new LiquidSiteSettingsAccessor())); o.MemberAccessStrategy.Register <LiquidSiteSettingsAccessor, FluidValue>(async(obj, name, context) => { var liquidTemplateContext = (LiquidTemplateContext)context; var siteService = liquidTemplateContext.Services.GetRequiredService <ISiteService>(); var site = await siteService.GetSiteSettingsAsync(); FluidValue result = name switch { nameof(ISite.SiteName) => new StringValue(site.SiteName), nameof(ISite.PageTitleFormat) => new StringValue(site.PageTitleFormat), nameof(ISite.SiteSalt) => new StringValue(site.SiteSalt), nameof(ISite.SuperUser) => new StringValue(site.SuperUser), nameof(ISite.Calendar) => new StringValue(site.Calendar), nameof(ISite.TimeZoneId) => new StringValue(site.TimeZoneId), nameof(ISite.ResourceDebugMode) => new StringValue(site.ResourceDebugMode.ToString()), nameof(ISite.UseCdn) => BooleanValue.Create(site.UseCdn), nameof(ISite.CdnBaseUrl) => new StringValue(site.CdnBaseUrl), nameof(ISite.PageSize) => NumberValue.Create(site.PageSize), nameof(ISite.MaxPageSize) => NumberValue.Create(site.MaxPageSize), nameof(ISite.MaxPagedCount) => NumberValue.Create(site.MaxPagedCount), nameof(ISite.BaseUrl) => new StringValue(site.BaseUrl), nameof(ISite.HomeRoute) => new ObjectValue(site.HomeRoute), nameof(ISite.AppendVersion) => BooleanValue.Create(site.AppendVersion), nameof(ISite.CacheMode) => new StringValue(site.CacheMode.ToString()), nameof(ISite.Properties) => new ObjectValue(site.Properties), _ => NilValue.Instance }; return(result); }); }); services.AddScoped <ISetupEventHandler, SetupEventHandler>(); services.AddScoped <IPermissionProvider, Permissions>(); services.AddScoped <IAuthorizationHandler, SuperUserHandler>(); services.AddRecipeExecutionStep <SettingsStep>(); services.AddSingleton <ISiteService, SiteService>(); // Site Settings editor services.AddScoped <IDisplayManager <ISite>, DisplayManager <ISite> >(); services.AddScoped <IDisplayDriver <ISite>, DefaultSiteSettingsDisplayDriver>(); services.AddScoped <IDisplayDriver <ISite>, ButtonsSettingsDisplayDriver>(); services.AddScoped <INavigationProvider, AdminMenu>(); services.AddScoped <ITimeZoneSelector, DefaultTimeZoneSelector>(); services.AddTransient <IDeploymentSource, SiteSettingsDeploymentSource>(); services.AddSingleton <IDeploymentStepFactory>(new DeploymentStepFactory <SiteSettingsDeploymentStep>()); services.AddScoped <IDisplayDriver <DeploymentStep>, SiteSettingsDeploymentStepDriver>(); services.AddScoped <IRecipeEnvironmentProvider, RecipeEnvironmentSiteNameProvider>(); }
public void NumberValueShouldCastDecinalValueWithCurrentCulture() { var input = $"1{CultureInfo.CurrentCulture.NumberFormat.NumberGroupSeparator}000{CultureInfo.CurrentCulture.NumberFormat.NumberDecimalSeparator}15"; var func = new NumberValue(); var result = func.Execute(FunctionsHelper.CreateArgs(input), _parsingContext); Assert.AreEqual(1000.15d, result.Result); }
/// <inheritdoc/> public virtual void Check() { _longHashCode = LongHashCodeWeights.BaseOperatorWeight ^ (ulong)Math.Abs(Kind.GetHashCode()); var sysDeffuzificatedValue = Defuzzificator.Defuzzificate(_kindOfDefuzzification, _a, _b, (double x) => SystemCall(x)); _deffuzificatedValue = new NumberValue(sysDeffuzificatedValue); }
public AmountEntry(SpeciesValue species, NumberValue initial, NumberValue initialVariance, string dimension, SampleValue sample) { this.species = species; this.initial = initial; this.initialVariance = initialVariance; this.dimension = dimension; this.sample = sample; }
public async ValueTask <FluidValue> ProcessAsync(FluidValue input, FilterArguments arguments, TemplateContext ctx) { var text = await GetTextAsync(input); var readTime = _readTimeCalculator.CalculateReadTime(text); return(NumberValue.Create(readTime)); }
public void Constructor_ShouldSetProperties_WhenNullValue() { var dut = new NumberValue(TestPlant, _fieldMock.Object, null); Assert.AreEqual(TestPlant, dut.Plant); Assert.AreEqual(FieldId, dut.FieldId); Assert.IsFalse(dut.Value.HasValue); }
public static NumberValue ConvertLogicalValueToNumberValue(LogicalValue source, IMainStorageContext mainStorageContext) { var result = new NumberValue(source.AsLogicalValue.SystemValue); FillAnnotationsModalitiesAndSections(source, result, mainStorageContext); return(result); }
public void NumberValueShouldCastDecinalValueWithSeparators() { var input = $"1,000.15"; var func = new NumberValue(); var result = func.Execute(FunctionsHelper.CreateArgs(input, ".", ","), _parsingContext); Assert.AreEqual(1000.15d, result.Result); }
public static NumberValue ConvertNullValueToNumberValue(NullValue source, IMainStorageContext mainStorageContext) { var result = new NumberValue(null); FillAnnotationsModalitiesAndSections(source, result, mainStorageContext); return(result); }
public void NumberValueShouldHandlePercentage() { var input = $"1,000.15%"; var func = new NumberValue(); var result = func.Execute(FunctionsHelper.CreateArgs(input, ".", ","), _parsingContext); Assert.AreEqual(10.0015d, result.Result); }
/// <summary> /// Returns the next compatible size constraint value from a start /// value.The values will be enumerated from lower values to /// higher. /// </summary> /// <param name="start">The initial start value</param> /// <returns>The next compatible value, or -1 if none exists</returns> public int NextValue(int start) { IEnumerable <IConstraint> list = this.Values; BigInteger val; // TODO: the constraint list should be sorted foreach (var c in list) { ValueConstraint vc = c as ValueConstraint; if (vc != null) { NumberValue nv = vc.Value as NumberValue; if (nv != null) { val = nv.Value; } else { val = 0; // TODO: need to handle this differently } } else { ValueRangeConstraint vrc = c as ValueRangeConstraint; if (vrc != null) { if (vrc.IsCompatible((BigInteger)start)) { return(start); } else { NumberValue nv = vrc.LowerBound as NumberValue; if (nv != null) { val = nv.Value; } else { // TODO: fix this throw new NotImplementedException(); } } } else { throw new NotImplementedException(); } } if ((BigInteger)start <= val) { return((int)val); } } return(-1); }
public override Value GetValue(UserItem item) { if (item.Item.CommunityRating.HasValue) { return(NumberValue.Create(item.Item.CommunityRating.GetValueOrDefault())); } return(Value.None); }
public Value Call(Value leftOperand, Value rightOperand, Value annotation, LocalCodeExecutionContext localCodeExecutionContext) { _logger.Info($"leftOperand = {leftOperand}"); _logger.Info($"rightOperand = {rightOperand}"); var result = new NumberValue(5); return(result); }
public static FluidValue Times(FluidValue input, FilterArguments arguments, TemplateContext context) { var first = arguments.At(0); var resultIsIntegral = input is NumberValue inputNumber && inputNumber.IsIntegral && first is NumberValue firstNumber && firstNumber.IsIntegral; return(NumberValue.Create(input.ToNumberValue() * first.ToNumberValue(), resultIsIntegral)); }
public override Value GetValue(UserItem item) { if (item.Item is Audio && item.Item.ParentIndexNumber.HasValue) { return(NumberValue.Create(item.Item.ParentIndexNumber.Value)); } return(Value.None); }
public override Value GetValue(UserItem item) { if (item.Item.ProductionYear.HasValue) { return(NumberValue.Create(item.Item.ProductionYear.Value)); } return(Value.None); }
public void ModuloWithNoArgumentThrows() { var input = NumberValue.Create(6); var arguments = FilterArguments.Empty; var context = new TemplateContext(); Assert.Throws <ParseException>(() => NumberFilters.Modulo(input, arguments, context)); }
public void Truncate(string input, int size, string output) { var source = new StringValue(input); var arguments = new FilterArguments().Add(NumberValue.Create(size)); var context = new TemplateContext(); var result = StringFilters.Truncate(source, arguments, context); Assert.Equal(output, result.Result.ToStringValue()); }
public static FluidValue Modulo(FluidValue input, FilterArguments arguments, TemplateContext context) { if (arguments.Count == 0) { throw new ParseException("The filter 'modulo' requires an argument."); } return(NumberValue.Create(Convert.ToInt32(input.ToNumberValue()) % Convert.ToInt32(arguments.At(0).ToNumberValue()))); }
public void Constructor_ShouldSetProperties_WhenDoubleValue() { var doubleValue = 1282.91; var dut = new NumberValue(TestPlant, _fieldMock.Object, doubleValue); Assert.AreEqual(TestPlant, dut.Plant); Assert.IsTrue(dut.Value.HasValue); Assert.AreEqual(doubleValue, dut.Value.Value); }
public void NumberValueShouldHandleMultiplePercentage() { var input = $"1,000.15%%"; var func = new NumberValue(); var result = func.Execute(FunctionsHelper.CreateArgs(input, ".", ","), _parsingContext); var r = System.Math.Round((double)result.Result, 15); Assert.AreEqual(0.100015d, r); }
public void Run(IEnvironment env) { var variable = new NumberValue(); env.CreateVariable(Name, variable); if (Value != null) { variable.Number = Value.Evaluate(env).Number; } }
public void TestGetTextValueNumberSetValue() { NumberValue numberValue1 = new NumberValue(); NumberValue numberValue2 = new NumberValue(); numberValue1.value = "1"; numberValue2.value = "2"; SetValue setValue = new SetValue(); setValue.values = new Value[] { numberValue1, numberValue2 }; Row row = new Row(); row.values = new Value[] { setValue }; string[] stringValues = PqlUtilities.GetRowStringValues(row); Assert.AreEqual(1, stringValues.Length); Assert.AreEqual("1,2", stringValues[0]); }
public NumberValue Part_002Dtime_0020Annual_0020Salary_Script(params IValue[] vals) { TrueFalseValue condResult = TrueFalseValue.Unanswered;Debug.Assert(vals.Length==0);NumberValue result = NumberValue.Unanswered;if (_rt.Unans) return result;_rt.PushScript("Part-time Annual Salary", ScriptType.Computation);if (_rt.InRpt && _rt.TopRptNdx <= 1){_Part_002Dtime_0020Annual_0020Salary_Sum = 0;}_rt.PushUnans();result = _rt.GetVarValueAllowUnans<NumberValue>("Hourly Salary") * new NumberValue(1040);_rt.PopUnans();if (_rt.InRpt){_Part_002Dtime_0020Annual_0020Salary_Sum += result;}_rt.PopScript();return result; }
public void HandleNumberParam() { var p1 = new NumberValue(18); Assert.AreEqual("18", p1.ToString()); var p2 = NumberValue.Parse("18"); Assert.AreEqual(18M, p2.Value); var p3 = NumberValue.Parse("18.00"); Assert.AreEqual(18.00M, p3.Value); var crit = Criterium.Parse("paramX=18.34"); var p4 = ((UntypedValue)crit.Operand).AsNumberValue(); Assert.AreEqual(18.34M, p4.Value); }
public void TestGetObjectNumberSetValue() { NumberValue numberValue1 = new NumberValue(); NumberValue numberValue2 = new NumberValue(); numberValue1.value = "1"; numberValue2.value = "2"; SetValue setValue = new SetValue(); setValue.values = new Value[] { numberValue1, numberValue2 }; List<object> value = PqlUtilities.GetValue(setValue) as List<object>; Assert.AreEqual(2, value.Count); Assert.True(value.Contains("1")); Assert.True(value.Contains("2")); }
private NumberCell(NumberCell cell) { this.value = cell.value; }
/// <summary> /// Adds a new decimal value to the list of query parameters. /// </summary> /// <param name="key">The parameter name.</param> /// <param name="value">The parameter value.</param> /// <returns>The statement builder, for chaining method calls.</returns> public StatementBuilder AddValue(string key, decimal value) { NumberValue queryValue = new NumberValue(); queryValue.value = value.ToString(); return AddValue(key, queryValue); }
public readonly NumberValue value; // Non-null #endregion Fields #region Constructors public NumberCell(double d) { Debug.Assert(!Double.IsNaN(d) && !Double.IsInfinity(d)); value = (NumberValue)NumberValue.Make(d); }