Beispiel #1
0
        public void TestAddRemoveObservations()
        {
            // arrange
            var simObservations = Range(1, 5, 2)
                                  .Map(
                id => new SimObservations(
                    10 + id,
                    100 + id,
                    $"subjectX",
                    $"refName{id:0000}",
                    Array(1d, 2, 3),
                    Array(4d, 5, 6)
                    )
                )
                                  .ToArr();
            var subject = new SimObservationsSet(simObservations.Head().Subject, simObservations);

            // act
            var(withAddition, added) = SimObservationsSet.AddObservations(subject, 100 + 2, $"refName{2:0000}", Array(7d, 8, 9), Array(10d, 11, 12));
            var withRemoval    = SimObservationsSet.RemoveObservations(withAddition, added);
            var withAllRemoved = SimObservationsSet.RemoveAllObservations(withAddition, 100 + 2);

            // assert
            Assert.IsTrue(withAddition.Observations.Count == 6);
            Assert.IsTrue(added.ID == 10 + (5 * 2 - 1) + 1);
            Assert.IsTrue(withAddition.Observations.Exists(o => o.RefName == $"refName{2:0000}"));
            Assert.AreEqual(subject, withRemoval);
            Assert.AreEqual(subject, withAllRemoved);
            Assert.IsFalse(subject.Equals(withAddition));
        }
Beispiel #2
0
        public void TestSimObservationsReferenceRoundTrip()
        {
            // arrange
            var evidenceSources = Range(1, 5, 2).Map(id =>
                                                     new SimEvidenceSource(
                                                         100 + id,
                                                         $"name{id:0000}",
                                                         $"desc{id:0000}",
                                                         toSet(Range(id, id).Map(s => $"subject{s:0000}")),
                                                         $"refName{id:0000}",
                                                         $"refHash{id:0000}"
                                                         )
                                                     )
                                  .ToArr();

            var observations = Range(1, 5, 2)
                               .Map(
                id => new SimObservations(
                    10 + id,
                    100 + id,
                    $"subjectX",
                    $"refName{id:0000}",
                    Array(1d, 2, 3),
                    Array(4d, 5, 6)
                    )
                )
                               .ToArr();

            var observationsSet = new SimObservationsSet(observations.Head().Subject, observations);

            var mockEvidence = new Mock <ISimEvidence>();

            mockEvidence.Setup(me => me.EvidenceSources).Returns(evidenceSources);
            mockEvidence.Setup(me => me.GetObservationSet(It.Is <string>(s => s == "subjectX"))).Returns(observationsSet);
            ISimEvidence evidence = mockEvidence.Object;

            SimEvidenceSource evidenceSource = evidenceSources.Skip(1).Take(1).Single();
            SimObservations   expected       = observations.Skip(1).Take(1).Single();

            // act
            var reference = evidence.GetReference(expected);
            var actual    = evidence.GetObservations(reference);

            // assert
            Assert.AreEqual(expected, actual);
        }