public void StaticConstructorWithNullArgumentReturnsValueWhenInputArgumentHasValueWhenBackingTypeIsDouble() { double?value = 1.0; Length?meter = Length.FromMeters(value); Assert.True(meter.HasValue); }
public Margin(Length?left, Length?top, Length?right, Length?bottom) { _top = top; _bottom = bottom; _left = left; _right = right; }
public void SumNullable() { var lengths = new Length?[] { Length.FromMetres(1), null, Length.FromMetres(2) }; var actual = lengths.Sum(); Assert.AreEqual(Length.FromMetres(3), actual); }
public void MaxNullable() { var lengths = new Length?[] { Length.FromMetres(1), Length.FromMetres(2), null }; var actual = lengths.Max(); Assert.AreEqual(Length.FromMetres(2), actual); }
public Margin(double?left, double?top, double?right, double?bottom) { _top = top.HasValue ? new Length(top.Value) : (Length?)null; _bottom = bottom.HasValue ? new Length(bottom.Value) : (Length?)null; _left = left.HasValue ? new Length(left.Value) : (Length?)null; _right = right.HasValue ? new Length(right.Value) : (Length?)null; }
public void AverageNullable() { var lengths = new Length?[] { Length.FromMetres(1), null, Length.FromMetres(2) }; var actual = lengths.Average(); Assert.AreEqual(Length.FromMetres(1.5), actual); }
void SetSlice(Length top, Length?right, Length?bottom, Length?left, Boolean fill) { _top = top; _right = right ?? _top; _bottom = bottom ?? _top; _left = left ?? _right; _fill = fill; }
int?Get(Length?value) { if (value.HasValue) { return(value.Value.Compute()); } return(null); }
public static bool TryParse(string s, out Length?l) { if (mReg.Match(s)?.Groups is GroupCollection gc && gc.Count > 2) { l = new Length(decimal.Parse(gc[1].Value), gc[2].Value); return(true); } l = null; return(false); }
public void NullLength_ShouldReturnNull() { // arrange Length?length = null; // act var result = -length; // assert result.Should().BeNull(); }
/// <summary> /// Creates a new route point. /// </summary> /// <param name="routeName">Name of the route</param> /// <param name="indexInRoute">The index of this point</param> /// <param name="totalPointsInRoute">The total number of points on this route</param> /// <param name="waypointName">The name of this waypoint</param> /// <param name="position">The position of the waypoint</param> /// <param name="bearingToNextWaypoint">The direction to the next waypoint (optional, will be calculated when the route is constructed)</param> /// <param name="distanceToNextWaypoint">The distance to the next waypoint (optional, will be calculated when the route is constructed)</param> /// <remarks> /// Route and point names should use ASCII characters only. Some devices may understand the extended ASCII code page (values > 127), /// but this is rare. Most devices will silently truncate any names longer than 10 chars. /// </remarks> public RoutePoint(string routeName, int indexInRoute, int totalPointsInRoute, string waypointName, GeographicPosition position, Angle?bearingToNextWaypoint, Length?distanceToNextWaypoint) { RouteName = routeName; IndexInRoute = indexInRoute; TotalPointsInRoute = totalPointsInRoute; WaypointName = waypointName; Position = position; BearingToNextWaypoint = bearingToNextWaypoint; DistanceToNextWaypoint = distanceToNextWaypoint; }
public void NullDenominator_ShouldThrow() { // arrange var nominator = CreateAreaInUnitOtherThan(AreaUnit.SquareMetre); Length?denominator = null; // act Func <Length?> result = () => nominator / denominator; // assert result.Should().Throw <DivideByZeroException>(); }
public void DivideByNull_ShouldThrow() { // arrange var length = CreateLengthInUnitOtherThan(LengthUnit.Metre); Length?denominator = null; // act Func <number> divideByZero = () => length / denominator; // assert divideByZero.Should().Throw <DivideByZeroException>(); }
public void NullLengths_ShouldReturnNull() { // arrange Length?nullLength1 = null; Length?nullLength2 = null; // act var result = nullLength1 - nullLength2; // assert result.Should().BeNull(); }
public void NullNominatorAndDenominator_ShouldThrow() { // arrange Volume?nominator = null; Length?denominator = null; // act Func <Area?> result = () => nominator / denominator; // assert result.Should().Throw <DivideByZeroException>(); }
public void NullDenominator_ShouldThrow() { // arrange var nominator = CreateVolumeInUnitOtherThan(VolumeUnit.CubicMetre); Length?denominator = null; // act Func <Area?> result = () => nominator / denominator; // assert result.Should().Throw <DivideByZeroException>(); }
public void NullArgumentAndFactor_ShouldReturnNull() { // arrange Length?argument = null; Length?factor = null; // act var result = argument * factor; // assert result.Should().BeNull(); }
/// <summary> /// Determines if the given value represents a valid state of this property. /// </summary> /// <param name="value">The state that should be used.</param> /// <returns>True if the state is valid, otherwise false.</returns> protected override Boolean IsValid(CSSValue value) { var width = value.ToLength(); if (width.HasValue) _width = width.Value; else if (value.Is("auto")) _width = null; else if (value != CSSValue.Inherit) return false; return true; }
public void NullFactor_ShouldTreatNullAsDefault() { // arrange var argument = CreateLengthInUnitOtherThan(LengthUnit.Metre); Length?factor = null; var expectedResult = argument * default(Length); // act var result = argument * factor; // assert result.Should().Be(expectedResult); }
public void NullLength_ShouldTreatNullAsDefault() { // arrange Length?nullLength = null; number denominator = (number)Fixture.CreateNonZeroNumber(); var expectedResult = default(Length) / denominator; // act var result = nullLength * denominator; // assert result.Should().NotBeNull(); result.Value.Should().Be(expectedResult); }
public void NullArgumentAndFactor_ShouldReturnNull() { // arrange Area? argument = null; Length?factor = null; // act var result1 = argument * factor; var result2 = factor * argument; // assert result1.Should().BeNull(); result2.Should().BeNull(); }
public void NullLength_ShouldTreatNullAsDefault() { // arrange Length?nullLength = null; number factor = Fixture.Create <number>(); var expectedResult = default(Length) * factor; // act var result = nullLength * factor; // assert result.Should().NotBeNull(); result.Value.Should().Be(expectedResult); }
public void NullFactor_ShouldTreatNullAsDefault() { // arrange var argument = CreateAreaInUnitOtherThan(AreaUnit.SquareMetre); Length?factor = null; var expectedResult = argument * default(Length); // act var result1 = argument * factor; var result2 = factor * argument; // assert result1.Should().Be(expectedResult); result2.Should().Be(expectedResult); }
public ScannedPassportInfo ParseInfoFromArray(IEnumerable <string> input) { var passportFields = input .SelectMany(s => s.Split(' ', StringSplitOptions.RemoveEmptyEntries)) .Select(s => s.Split(':')) .ToDictionary(s => s[0], s => s[1]); int?birthYear = int.TryParse(GetFieldValueOrNull(passportFields, BirthYearName), out int byr) ? (int?)byr : default; int?issueYear = int.TryParse(GetFieldValueOrNull(passportFields, IssueYearName), out int iyr) ? (int?)iyr : default; int?expirationYear = int.TryParse(GetFieldValueOrNull(passportFields, ExpirationYearName), out int eyr) ? (int?)eyr : default; string?heightString = GetFieldValueOrNull(passportFields, HeightName); Length?height = Length.FromString(heightString); var hairColor = Color.FromHexString(GetFieldValueOrNull(passportFields, HairColorName)); var eyeColor = Enum.TryParse <EyeColor>(GetFieldValueOrNull(passportFields, EyeColorName), true, out var ecl) ? (EyeColor?)ecl : EyeColor.Unknown; var passportId = GetFieldValueOrNull(passportFields, PassportIdName); int?countryId = int.TryParse(GetFieldValueOrNull(passportFields, CountryIdName), out int cid) ? (int?)cid : default; return(new ScannedPassportInfo( birthYear, issueYear, expirationYear, height, hairColor, eyeColor, passportId, countryId )); }
protected override Boolean IsValid(CSSValue value) { if (value.Is("normal")) { _spacing = null; } else if (value.ToLength().HasValue) { _spacing = value.ToLength(); } else if (value != CSSValue.Inherit) { return(false); } return(true); }
/// <summary> /// Determines if the given value represents a valid state of this property. /// </summary> /// <param name="value">The state that should be used.</param> /// <returns>True if the state is valid, otherwise false.</returns> protected override Boolean IsValid(CSSValue value) { if (value.Is(Keywords.Normal)) { _spacing = null; } else if (value.ToLength().HasValue) { _spacing = value.ToLength(); } else { return(false); } return(true); }
/// <summary> /// Determines if the given value represents a valid state of this property. /// </summary> /// <param name="value">The state that should be used.</param> /// <returns>True if the state is valid, otherwise false.</returns> protected override Boolean IsValid(CSSValue value) { var width = value.ToLength(); if (width.HasValue) { _width = width.Value; } else if (value.Is(Keywords.Auto)) { _width = null; } else { return(false); } return(true); }
protected override Boolean IsValid(CSSValue value) { var width = value.ToLength(); if (width.HasValue) { _width = width.Value; } else if (value.Is("auto")) { _width = null; } else if (value != CSSValue.Inherit) { return(false); } return(true); }
public void NullAndLength_ShouldTreatNullAsDefault() { // arrange Length?nullLength = null; var length = CreateLengthInUnitOtherThan(LengthUnit.Metre); // act var result1 = length - nullLength; var result2 = nullLength - length; // assert result1.Should().NotBeNull(); result1.Value.Metres.Should().Be(length.Metres); result1.Value.Unit.Should().Be(length.Unit); result2.Should().NotBeNull(); result2.Value.Metres.Should().Be(-length.Metres); result2.Value.Unit.Should().Be(length.Unit); }
public ScannedPassportInfo ( int?birthYear, int?issueYear, int?expirationYear, Length?height, Color?hairColor, EyeColor?eyeColor, string?passportId, int?countryId ) { BirthYear = birthYear; IssueYear = issueYear; ExpirationYear = expirationYear; Height = height; HairColor = hairColor; EyeColor = eyeColor; PassportId = passportId; CountryId = countryId; }
public void MultipleSerialConversion_ShouldHaveSameValueAtTheEnd() { // arrange var units = new List <LengthUnit> { LengthUnit.Metre, LengthUnit.Millimetre, LengthUnit.Kilometre, LengthUnit.Foot, LengthUnit.Inch, LengthUnit.Metre }; var initialLength = new Length((number)0.12345678m, units.First()); Length?finalLength = null; // act units.ForEach(u => finalLength = (finalLength ?? initialLength).Convert(u)); // assert finalLength.Should().Be(initialLength); }
/// <summary> /// Determines if the given value represents a valid state of this property. /// </summary> /// <param name="value">The state that should be used.</param> /// <returns>True if the state is valid, otherwise false.</returns> protected override Boolean IsValid(CSSValue value) { if (value == CSSValue.Inherit) return true; var values = value as CSSValueList ?? new CSSValueList(value); if (values.Length > 4) return false; var widths = new Length?[4]; for (int i = 0; i < values.Length; i++) { var width = values[i].ToBorderWidth(); if (!width.HasValue) return false; widths[i] = width; } if (!widths[1].HasValue) widths[1] = widths[0]; if (!widths[2].HasValue) widths[2] = widths[0]; if (!widths[3].HasValue) widths[3] = widths[1]; _top = widths[0].Value; _right = widths[1].Value; _bottom = widths[2].Value; _left = widths[3].Value; return true; }
internal CSSColumnWidthProperty() : base(PropertyNames.ColumnWidth) { _width = null; _inherited = false; }