Пример #1
0
 public void Substring_Regex(string original, string pattern, string expected_before, string expected_after)
 {
     AssertAll.Of(
         () => Assert.That(original.SubstringBefore(new Regex(pattern)), Is.EqualTo(expected_before)),
         () => Assert.That(original.SubstringAfter(new Regex(pattern)), Is.EqualTo(expected_after))
         );
 }
Пример #2
0
 public void JonPath_Simple(string parent, string child, string expected)
 {
     AssertAll.Of(
         () => Assert.That(BPath.JoinPath(parent, child), Is.EqualTo(expected)),
         () => Assert.That(BPath.JoinPath(new[] { parent, child }), Is.EqualTo(expected))
         );
 }
Пример #3
0
        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")
                );
        }
Пример #4
0
        public void TruncateLines(
            [Values(1, 5, 10, 50, 100)]
            int lineCount,
            [Values(1, 2, 10, 50, 100)]
            int truncateTo,
            [Values(true, false)]
            bool includeMessage
            )
        {
            var ln            = Enumerable.Repeat("LINE", lineCount);
            var truncated     = ln.TruncateLines(truncateTo, includeMessage);
            var truncateCount = lineCount - truncateTo;

            if (lineCount > truncateTo)
            {
                AssertAll.Of(
                    () => Assert.That(truncated, Has.Length.EqualTo(truncateTo)),
                    () => {
                    if (includeMessage)
                    {
                        AssertAll.Of(
                            () => Assert.That(truncated.Last(), Is.Not.EqualTo("LINE")),
                            () => Assert.That(truncated.Last(), Contains.Substring(truncateCount + ""))
                            );
                    }
                }
                    );
            }
            else if (lineCount <= truncateTo)
            {
                Assert.That(truncated, Is.EqualTo(ln));
            }
        }
Пример #5
0
        public IEnumerator LoadTimeUnaffectedBySaving()
        {
            var beforeNewSave = DateTime.Now;

            yield return(null);

            var saveData     = SaveDataTestImpl.NewSaveFile(nameof(LoadTimeUnaffectedBySaving));
            var afterNewSave = DateTime.Now;

            AssertAll.Of(
                () => Assert.That(saveData.LastSaveTime, Is.InRange(beforeNewSave, afterNewSave)),
                () => Assert.That(saveData.LastLoadTime, Is.Null)
                );

            var oldSaveTime = saveData.LastSaveTime;
            var oldLoadTime = saveData.LastLoadTime;

            yield return(new WaitForSecondsRealtime(1));

            var beforeReSave = DateTime.Now;

            yield return(null);

            saveData.Save(false);
            var afterReSave = DateTime.Now;

            AssertAll.Of(
                () => Assert.That(saveData.LastSaveTime, Is.InRange(beforeReSave, afterReSave)),
                () => Assert.That(saveData.LastSaveTime, Is.Not.EqualTo(oldSaveTime)),
                () => Assert.That(saveData.LastLoadTime, Is.EqualTo(oldLoadTime))
                );
        }
Пример #6
0
        public IEnumerator SaveTimeUnaffectedByLoading()
        {
            DateTime beforeNewSave = DateTime.Now;

            yield return(null);

            var      saveData     = SaveDataTestImpl.NewSaveFile(nameof(SaveTimeUnaffectedByLoading));
            DateTime afterNewSave = DateTime.Now;

            AssertAll.Of(
                () => Assert.That(saveData.LastSaveTime, Is.InRange(beforeNewSave, afterNewSave)),
                () => Assert.That(saveData.LastLoadTime, Is.Null)
                );

            var oldSaveTime = saveData.LastSaveTime;
            var oldLoadTime = saveData.LastLoadTime;

            yield return(new WaitForSecondsRealtime(1));

            DateTime beforeReload = DateTime.Now;

            yield return(null);

            saveData.Reload();
            DateTime afterReload = DateTime.Now;

            AssertAll.Of(
                () => Assert.That(saveData.LastSaveTime, Is.EqualTo(oldSaveTime), $"The {nameof(SaveDataTestImpl.LastSaveTime)} should not have changed, because we {nameof(SaveDataTestImpl.Reload)}-ed without {nameof(SaveDataTestImpl.Save)}-ing!"),
                () => Assert.That(saveData.LastLoadTime, Is.Not.EqualTo(oldLoadTime), $"The {nameof(SaveDataTestImpl.LastLoadTime)} should have changed, because we {nameof(SaveDataTestImpl.Reload)}-ed!"),
                () => Assert.That(saveData.LastLoadTime, Is.InRange(beforeReload, afterReload))
                );
        }
Пример #7
0
        public void TestSerializeThrowables()
        {
            const string            nickName = nameof(TestSerializeThrowables);
            FortuneFountainSaveData fortuneFountainSaveData = FortuneFountainSaveData.NewSaveFile(nickName);

            for (int i = 0; i < ValuableDatabase.ValuableTypes.Length; i++)
            {
                // copying `i` into `index` inside the loop 'cus otherwise lambdas can get messed up
                var index        = i;
                var karmaValue   = Random.Range(1, 25);
                var valuableType = ValuableDatabase.ValuableTypes[index];
                Log($"Grabbing a {valuableType} with a value of {karmaValue}");
                fortuneFountainSaveData.Hand.AddToHand(new ThrowableValuable(valuableType, karmaValue));
                fortuneFountainSaveData.Save(useReSaveDelay: false);

                Log($"before loading throwables:", fortuneFountainSaveData.Hand.Throwables.JoinLines());

                //load the save data we created
                FortuneFountainSaveData loadedSaveData = FortuneFountainSaveData.Load(nickName);

                Log($"original SaveData:", fortuneFountainSaveData);
                Log($"loaded SaveData:", loadedSaveData);

                AssertAll.Of(
                    () => Assert.That(loadedSaveData.ToJson(), Contains.Substring($"\"{nameof(Hand._throwables)}\":")),
                    () => Assert.That(loadedSaveData.Hand.Throwables.Count, Is.EqualTo(index + 1)),
                    () => Assert.That(loadedSaveData.Hand.Throwables[index] as ThrowableValuable,
                                      Has.Property(nameof(ThrowableValuable.ValuableType)).EqualTo(valuableType)),
                    () => Assert.That(loadedSaveData.Hand.Throwables[index] as ThrowableValuable,
                                      Has.Property(nameof(ThrowableValuable.PresentValue)).EqualTo(karmaValue))
                    );
            }
        }
Пример #8
0
 public static void IsAutoProperty(this PropertyInfo propertyInfo)
 {
     AssertAll.Of(
         () => Assert.That(propertyInfo.BackingField(), Is.Not.Null),
         () => Assert.That(propertyInfo.BackingField()?.IsAutoPropertyBackingField(), Is.True),
         () => BacksProperty(propertyInfo.BackingField(), propertyInfo)
         );
 }
Пример #9
0
 private static void IsBackedBy([CanBeNull] this PropertyInfo propertyInfo, [CanBeNull] FieldInfo expectedBackingField)
 {
     AssertAll.Of(
         $"{propertyInfo.Prettify()} should have the backing field {expectedBackingField.Prettify()}",
         () => Assert.That(propertyInfo?.BackingField(), Is.Not.Null.And.EqualTo(expectedBackingField)),
         () => BacksProperty(expectedBackingField, propertyInfo)
         );
 }
Пример #10
0
 public void Fill_NegativeLength()
 {
     AssertAll.Of(
         () => Assert.Throws <ArgumentOutOfRangeException>(() => "a".FillRight(-1, "a")),
         () => Assert.Throws <ArgumentOutOfRangeException>(() => "a".FillLeft(-1, "a")),
         () => Assert.Throws <ArgumentOutOfRangeException>(() => "a".Fill(-1))
         );
 }
Пример #11
0
 public static void PassedFailable <T>(FailableFunc <T> failableFunc)
 {
     AssertAll.Of(
         () => Assert.That(failableFunc, Has.Property(nameof(failableFunc.HasValue)).True),
         () => Assert.That(failableFunc, Has.Property(nameof(failableFunc.Failed)).False),
         () => Assert.DoesNotThrow(() => Console.WriteLine(failableFunc.Value)),
         () => Assert.Throws <InvalidOperationException>(() => Console.WriteLine(failableFunc.Excuse))
         );
 }
Пример #12
0
        public void MustContain_WithDuplicates()
        {
            var set = EnumSet.Of(EnumWithDuplicates.Crimson, EnumWithDuplicates.Blue);

            AssertAll.Of(
                () => Assert.DoesNotThrow(() => set.MustContain(EnumWithDuplicates.Crimson)),
                () => Assert.DoesNotThrow(() => set.MustContain(EnumWithDuplicates.Red))
                );
        }
Пример #13
0
        public void TestSaveFilePathsAreSortedChronologically()
        {
            var loadedSaves = SaveDataTestImpl.GetAllSaveFilePaths(DummyNickName);

            AssertAll.Of(
                () => Assert.AreNotEqual(0, loadedSaves.Length, "No saves were actually loaded!"),
                () => Assert.AreEqual(DummySaveFiles, loadedSaves)
                );
        }
Пример #14
0
 public void Test_Compute()
 {
     AssertAll.Of(
         $"{nameof(Coercively)}.{nameof(Coercively.Compute)}: [{AType.Name}]{A} {Operation} [{BType.Name}]{B} == [{EType.Name}]{E}",
         Coercively.Compute(A, Operation, B),
         Is.EqualTo(E),
         Is.TypeOf(EType)
         );
 }
Пример #15
0
        public void File_To_Uri(string file)
        {
            var fi = new FileInfo(file);

            AssertAll.Of(
                () => Assert.That(fi.ToUri(), Has.Property(nameof(Uri.IsFile)).True),
                () => Assert.That(fi.ToUri().AbsolutePath, Is.EqualTo(BPath.NormalizeSeparators(fi.FullName)))
                );
        }
Пример #16
0
        public void StepExclusive(float min, float max, int stepCount, params float[] expectedResults)
        {
            var steps = Bloop.StepExclusive(min, max, stepCount);

            AssertAll.Of(
                () => Assert.That(steps, Is.EqualTo(expectedResults)),
                () => Assert.That(steps, Is.EquivalentTo(expectedResults))
                );
        }
Пример #17
0
 public static void SaveFile_Basic <T>(SaveFile <T> saveFile, string expectedName, DateTime expectedTimeStamp) where T : ISaveData
 {
     AssertAll.Of(
         saveFile,
         Has.Property(nameof(saveFile.Nickname)).EqualTo(expectedName),
         Has.Property(nameof(saveFile.TimeStamp)).EqualTo(expectedTimeStamp),
         Has.Property(nameof(saveFile.FileSystemInfo)).With.Property(nameof(FileSystemInfo.Name)).EqualTo($"{expectedName}_{expectedTimeStamp.Ticks}{SaveFileName.DefaultExtension}")
         );
 }
Пример #18
0
 public static void Equality <T>(FailableFunc <T> failableFunc, T expectedValue, bool expectedEquality)
 {
     AssertAll.Of(
         () => Assert.That(failableFunc == expectedValue, Is.EqualTo(expectedEquality), "failable == expectedValue"),
         () => Assert.That(expectedValue == failableFunc, Is.EqualTo(expectedEquality), "expectedValue == failable"),
         () => Assert.That(failableFunc.Equals(expectedValue), Is.EqualTo(expectedEquality), "failable.Equals(expectedValue)"),
         () => Assert.That(Optional.AreEqual(failableFunc, expectedValue), Is.EqualTo(expectedEquality), "Optional.AreEqual(failable, expectedValue)"),
         () => Assert.That(Optional.AreEqual(expectedValue, failableFunc), Is.EqualTo(expectedEquality), "Optional.AreEqual(expectedValue, failable)")
         );
 }
Пример #19
0
        public void SuccessfulFailableInequality()
        {
            var failable = Optional.Try(Succeed);
            var optional = Optional.Of(Unexpected_Value);

            AssertAll.Of(
                () => Validate.Equality(failable, optional, false),
                () => Validate.Equality(failable, Unexpected_Value, false)
                );
        }
Пример #20
0
        public void SuccessfulFailableEquality()
        {
            var failable = Optional.Try(Succeed);
            var optional = Optional.Of(Expected_Value);

            AssertAll.Of(
                () => Validate.Equality(failable, optional, true),
                () => Validate.Equality(failable, Expected_Value, true)
                );
        }
Пример #21
0
        public void EquivalencyWithMismatchedOrder()
        {
            var backwardsWeekend = new EnumSet <DayOfWeek>(DayOfWeek.Sunday, DayOfWeek.Saturday);

            AssertAll.Of(
                backwardsWeekend,
                Is.Not.EqualTo(GetWeekend()),
                Is.EquivalentTo(GetWeekend())
                );
        }
Пример #22
0
 public static void Equality <T>(FailableFunc <T> a, FailableFunc <T> b, bool expectedEquality)
 {
     AssertAll.Of(
         () => Assert.That(a == b, Is.EqualTo(expectedEquality), "a == b"),
         () => Assert.That(b == a, Is.EqualTo(expectedEquality), "b == a"),
         () => Assert.That(a.Equals(b), Is.EqualTo(expectedEquality), "a.Equals(b)"),
         () => Assert.That(b.Equals(a), Is.EqualTo(expectedEquality), "b.Equals(a)"),
         () => Assert.That(Optional.AreEqual(a, b), Is.EqualTo(expectedEquality), "Optional.AreEqual(a,b)"),
         () => Assert.That(Optional.AreEqual(b, a), Is.EqualTo(expectedEquality), "Optional.AreEqual(b,a)")
         );
 }
Пример #23
0
        public void FailedFailableEquality()
        {
            var failable = Optional.Try(Fail);
            var optional = new Optional <int>();

            AssertAll.Of(
                () => Validate.Equality(failable, optional, true),
                () => Validate.Equality(failable, failable, true),
                () => Validate.Equality(failable, Optional.Try(Fail), true)
                );
        }
Пример #24
0
        public void FailedFailableInequality()
        {
            var failable = Optional.Try(Fail);
            var optional = Optional.Of(Expected_Value);

            AssertAll.Of(
                () => Validate.Equality(failable, optional, false),
                () => Validate.Equality(failable, Expected_Value, false),
                () => Validate.Equality(failable, Optional.Try(Succeed), false)
                );
        }
Пример #25
0
        public void SaveFileName_Parse([ValueSource(nameof(GetExpectations))] SaveFileNameExpectation expectation)
        {
            var sfn = SaveFileName.Parse(expectation.RenderedName);

            AssertAll.Of(
                () => Assert.That(sfn.Rendered, Is.EqualTo(expectation.RenderedName)),
                () => Assert.That(sfn.Nickname, Is.EqualTo(expectation.Nickname)),
                () => Assert.That(sfn.TimeStamp, Is.EqualTo(expectation.TimeStamp)),
                () => Assert.That(sfn.FullExtension, Is.EqualTo(expectation.Extension.PrefixIfMissing(".")))
                );
        }
Пример #26
0
        public void FailableSuccessObjectInequality()
        {
            var failable  = Optional.Try(Succeed);
            var failable2 = Optional.Try(UnexpectedSuccess);

            AssertAll.Of(
                () => Validate.ObjectEquality(failable, Unexpected_Value, false),
                () => Validate.ObjectEquality(failable, failable2, false),
                () => Validate.ObjectEquality(failable, null, false)
                );
        }
Пример #27
0
        public void EmptyObjectIsCorrect()
        {
            var saveData  = new SaveDataTestImpl(nameof(EmptyObjectIsCorrect));
            var emptySave = SaveDataTestImpl.EmptySaveData.Value;

            AssertAll.Of(
                () => Assert.That(emptySave.Word, Is.EqualTo(saveData.Word)),
                () => Assert.That(emptySave.Word2, Is.EqualTo(saveData.Word2)),
                () => Assert.That(emptySave, Has.Property(nameof(emptySave.LastLoadTime)).Null)
                );
        }
Пример #28
0
 public void Fill_NullFiller(
     [Values(0, 1, 2, 3)]
     int desiredLength
     )
 {
     AssertAll.Of(
         () => Assert.Throws <ArgumentNullException>(() => "".FillRight(desiredLength, null)),
         () => Assert.Throws <ArgumentNullException>(() => "".FillLeft(desiredLength, null)),
         () => Assert.Throws <ArgumentNullException>(() => StringUtils.Fill(null, desiredLength))
         );
 }
Пример #29
0
        public void DefaultEqualsEmpty()
        {
            Optional <int> a = default;

            Console.WriteLine(a);

            AssertAll.Of(
                a,
                Has.Property(nameof(a.HasValue)).EqualTo(false),
                Is.EqualTo(new Optional <int>())
                );
        }
Пример #30
0
 public static void Equality <T>(FailableFunc <T> failableFunc, Optional <T> optional, bool expectedEquality)
 {
     AssertAll.Of(
         () => Assert.That(failableFunc == optional, Is.EqualTo(expectedEquality), "failable == optional"),
         // no longer supported through ==
         // () => Assert.That(optional     == failableFunc,                  Is.EqualTo(expectedEquality), "optional == failable"),
         () => Assert.That(failableFunc.Equals(optional), Is.EqualTo(expectedEquality), "failable.Equals(optional)"),
         () => Assert.That(optional.Equals(failableFunc), Is.EqualTo(expectedEquality), "optional.Equals(failable)"),
         () => Assert.That(Optional.AreEqual(optional, failableFunc), Is.EqualTo(expectedEquality), "Optional.AreEqual(optional, failable)"),
         () => Assert.That(Optional.AreEqual(failableFunc, optional), Is.EqualTo(expectedEquality), "Optional.AreEqual(failable, optional)")
         );
 }