public void ShouldGetSetSegmentValueOptionsWhenValuesHaventGenerated(RangeDomainSegmentOptions option) { _subject = new RangeDomainSegment(_mockRandom.Object, 0, 10); _subject.SegmentValueOptions = option; Assert.AreEqual(option, _subject.SegmentValueOptions); }
public void ShouldThrowExceptionWhenOptionsChangedAfterGetValuesInvoked() { _subject = new RangeDomainSegment(_mockRandom.Object, 0, 10); _subject.GetValues(_subject.MaxNumberOfValuesInSegment); Assert.Throws(typeof(NotSupportedException), () => _subject.SetMaximumAllowedValue(100)); }
public void ShouldWriteJsonAndDeserializeIntoSameObject() { MathDomain original = new MathDomain(); ValueDomainSegment vds = new ValueDomainSegment(1024); RangeDomainSegment rds = new RangeDomainSegment(new Random800_90(), 0, 1024, 128); original.AddSegment(vds); original.AddSegment(rds); var serializedObject = JsonConvert.SerializeObject( original, new JsonSerializerSettings { Converters = new List <JsonConverter> { new DomainConverter() }, NullValueHandling = NullValueHandling.Ignore } ); var deserializedObject = JsonConvert.DeserializeObject <MathDomain>( serializedObject, new DomainConverter() ); var vdsReObjectified = deserializedObject.DomainSegments.OfType <ValueDomainSegment>().First(); var rdsReObjectified = deserializedObject.DomainSegments.OfType <RangeDomainSegment>().First(); Assert.AreEqual(original.DomainSegments.Count(), deserializedObject.DomainSegments.Count(), "count"); Assert.AreEqual(vds.ToString(), vdsReObjectified.ToString(), nameof(vds)); Assert.AreEqual(rds.ToString(), rdsReObjectified.ToString(), nameof(rds)); }
public void ShouldProduceValuesWithConditionBoundToDomain() { _subject = new RangeDomainSegment(new Random800_90(), 8, 128, 8); var values = _subject.GetValues(v => v > 64, 10); Assert.IsTrue(values.All(a => a % 8 == 0)); }
public void ShouldReturnCorrectMaximumAvailableInSegment(int min, int max, int increment, int expectation) { _subject = new RangeDomainSegment(_mockRandom.Object, min, max, increment); var result = _subject.MaxNumberOfValuesInSegment; Assert.AreEqual(expectation, result); }
public void ShouldReturnCorrectResponseIfNumberIncludedInRange(int min, int max, int increment, int numberToCheck, bool expectation) { _subject = new RangeDomainSegment(_mockRandom.Object, min, max, increment); var result = _subject.IsWithinDomain(numberToCheck); Assert.AreEqual(expectation, result); }
public void ShouldReturnProperMinMaxAsSetInConstructor(int min, int max) { _subject = new RangeDomainSegment(_mockRandom.Object, min, max); var result = _subject.RangeMinMax; Assert.AreEqual(min, result.Minimum, nameof(min)); Assert.AreEqual(max, result.Maximum, nameof(max)); }
public void ShouldThrowExceptionWhenChangingOptionsAfterGetValues() { _subject = new RangeDomainSegment(_mockRandom.Object, 0, 10); _subject.SegmentValueOptions = RangeDomainSegmentOptions.Sequential; _subject.GetValues(_subject.MaxNumberOfValuesInSegment); Assert.Throws(typeof(NotSupportedException), () => _subject.SegmentValueOptions = RangeDomainSegmentOptions.Sequential); }
public void ShouldReturnNumbersOnlyUpToMaximumAvailable(int min, int max, int increment) { _subject = new RangeDomainSegment(_mockRandom.Object, min, max, increment) { SegmentValueOptions = RangeDomainSegmentOptions.Sequential }; int maxQuantityAvailable = _subject.MaxNumberOfValuesInSegment; var result = _subject.GetValues(maxQuantityAvailable).ToList(); Assert.AreEqual(_subject.MaxNumberOfValuesInSegment, result.Count); }
public void ShouldSetInstanceMaxIfParamMaxIsGreaterThanValue(int originalValue, int maxValue) { _subject = new RangeDomainSegment(_mockRandom.Object, 0, originalValue); _subject.SetMaximumAllowedValue(maxValue); if (originalValue > maxValue) { Assert.AreEqual(maxValue, _subject.RangeMinMax.Maximum); } else { Assert.AreEqual(originalValue, _subject.RangeMinMax.Maximum); } }
public void ShouldReturnValuesThatMatchAGivenCondition(int min, int max, int increment) { _subject = new RangeDomainSegment(new Random800_90(), min, max, increment) { SegmentValueOptions = RangeDomainSegmentOptions.Random }; var result = _subject.GetValues(v => v % 8 == 0, 10); Assert.LessOrEqual(result.Count(), 10); foreach (var value in result) { Assert.IsTrue(value % 8 == 0); } }
public void ShouldReturnValidNumbersWithinRangeRandomlySanityCheck(string testLabel, int min, int max, int increment, int seedRandom, int quantityToReturn, int[] expectation) { // Random should always return the "seedRandom" in order to test the +/- logic _mockRandom .Setup(s => s.GetRandomInt(It.IsAny <int>(), It.IsAny <int>())) .Returns(seedRandom); _subject = new RangeDomainSegment(_mockRandom.Object, min, max, increment) { SegmentValueOptions = RangeDomainSegmentOptions.Random }; var result = _subject.GetValues(min, max, quantityToReturn); Assert.AreEqual(expectation.ToList(), result.ToList()); }
public void ShouldReturnNumbersInSequenceSubsetRangeSanityCheck(int min, int max, int increment, int[] expectation) { _subject = new RangeDomainSegment(_mockRandom.Object, min, max, increment) { SegmentValueOptions = RangeDomainSegmentOptions.Sequential }; var maxQuantityAvailable = _subject.MaxNumberOfValuesInSegment; var result = _subject.GetValues(min, max, maxQuantityAvailable).ToList(); for (int i = 0; i < expectation.Length; i++) { Assert.AreEqual(expectation[i], result[i]); } }
public void ShouldReturnSequentialValuesOnlyWithinSubsets() { _subject = new RangeDomainSegment(_mockRandom.Object, 0, 10) { SegmentValueOptions = RangeDomainSegmentOptions.Sequential }; int minSubset = 0; int maxSubset = 4; int[] expectedValues = { 0, 1, 2, 3, 4 }; var maxQuantityAvailable = _subject.MaxNumberOfValuesInSegment; var result = _subject.GetValues(minSubset, maxSubset, maxQuantityAvailable).ToList(); Assert.IsTrue(expectedValues.OrderBy(t => t).SequenceEqual(result.OrderBy(t => t))); }
public void ShouldAlwaysPullMaximumNumberOfValuesWithACondition(int min, int max, int increment) { _subject = new RangeDomainSegment(new Random800_90(), min, max, increment) { SegmentValueOptions = RangeDomainSegmentOptions.Random }; for (var i = 0; i < 100; i++) { var result = _subject.GetValues(v => v % 128 == 0, 5); Assert.AreEqual(result.Count(), 5, "pulled not enough mod 128"); } for (var i = 0; i < 100; i++) { var result = _subject.GetValues(v => v % 128 != 0, 5); Assert.AreEqual(result.Count(), 5, "pulled not enough not mod 128"); } }
public void ShouldWriteJsonAndDeserializeIntoSameObject() { MathDomain original = new MathDomain(); ValueDomainSegment vds = new ValueDomainSegment(1024); RangeDomainSegment rds = new RangeDomainSegment(new Random800_90(), 0, 1024, 128); original.AddSegment(vds); original.AddSegment(rds); var serializedObject = JsonSerializer.Serialize(original, _jsonSerializerOptions); var deserializedObject = JsonSerializer.Deserialize <MathDomain>(serializedObject, _jsonSerializerOptions); Assert.IsNotNull(deserializedObject, $"{nameof(deserializedObject)} was null."); var vdsReObjectified = deserializedObject.DomainSegments.OfType <ValueDomainSegment>().First(); var rdsReObjectified = deserializedObject.DomainSegments.OfType <RangeDomainSegment>().First(); Assert.AreEqual(original.DomainSegments.Count(), deserializedObject.DomainSegments.Count(), "count"); Assert.AreEqual(vds.ToString(), vdsReObjectified.ToString(), nameof(vds)); Assert.AreEqual(rds.ToString(), rdsReObjectified.ToString(), nameof(rds)); }
public void ShouldReturnRandomValuesOnlyWithinSubsets() { // Random should always return the "seedRandom" in order to test the +/- logic _mockRandom .Setup(s => s.GetRandomInt(It.IsAny <int>(), It.IsAny <int>())) .Returns(0); _subject = new RangeDomainSegment(_mockRandom.Object, 0, 10) { SegmentValueOptions = RangeDomainSegmentOptions.Random }; int minSubset = 0; int maxSubset = 4; int[] expectedValues = { 0, 1, 2, 3, 4 }; var maxQuantityAvailable = _subject.MaxNumberOfValuesInSegment; var result = _subject.GetValues(minSubset, maxSubset, maxQuantityAvailable); Assert.AreEqual(expectedValues.ToList(), result.ToList()); }
public void ShouldThrowExceptionWhenMinGreaterThanMax(int min, int max) { Assert.Throws(typeof(ArgumentException), () => _subject = new RangeDomainSegment(_mockRandom.Object, min, max)); }
public void ShouldThrowExceptionWhenIncrementLessThanOne(int increment) { Assert.Throws(typeof(ArgumentException), () => _subject = new RangeDomainSegment(_mockRandom.Object, 1, 100, increment)); }
public void ShouldBeSequentialByDefault() { _subject = new RangeDomainSegment(_mockRandom.Object, 0, 10); Assert.AreEqual(RangeDomainSegmentOptions.Sequential, _subject.SegmentValueOptions); }
public void ShouldThrowExceptionWhenMaxMinusMinLessThanIncrement(int min, int max, int increment) { Assert.Throws(typeof(ArgumentException), () => _subject = new RangeDomainSegment(_mockRandom.Object, min, max, increment)); }