public async Task WhenTwoPersonsStartsFromOneRoomAndSplitToTwoOthersNumbersOfPeopleShouldBeCorrect() { var(motionEvents, scheduler, lampDictionary) = new LightAutomationServiceBuilder(_context).WithMotion ( OnNext(Time.Tics(1000), new MotionEnvelope(Detectors.livingRoomDetector)), OnNext(Time.Tics(2000), new MotionEnvelope(Detectors.hallwayDetectorLivingRoom)), OnNext(Time.Tics(2900), new MotionEnvelope(Detectors.bathroomDetector)), OnNext(Time.Tics(3000), new MotionEnvelope(Detectors.hallwayDetectorToilet)), OnNext(Time.Tics(4000), new MotionEnvelope(Detectors.kitchenDetector)) ).Build(); scheduler.AdvanceJustAfter(TimeSpan.FromSeconds(4)); var status = await _context.Query <MotionStatus>(MotionServiceStatusQuery.Create()); Assert.AreEqual(1, await _context.Query <int>(NumberOfPeopleQuery.Create(Detectors.kitchenDetector))); Assert.AreEqual(1, await _context.Query <int>(NumberOfPeopleQuery.Create(Detectors.bathroomDetector))); // Assert.AreEqual(2, status.NumberOfPersonsInHouse); Assert.AreEqual(true, lampDictionary[Detectors.kitchenDetector].IsTurnedOn); Assert.AreEqual(true, lampDictionary[Detectors.bathroomDetector].IsTurnedOn); Assert.AreEqual(false, lampDictionary[Detectors.hallwayDetectorLivingRoom].IsTurnedOn); //Assert.AreEqual(false, lampDictionary[Detectors.livingRoomDetector].IsTurnedOn); scheduler.AdvanceJustAfter(TimeSpan.FromSeconds(5)); Assert.AreEqual(false, lampDictionary[Detectors.hallwayDetectorToilet].IsTurnedOn); }
public async Task Count_WhenCrossPassing_ShouldCountNumberOfPeople() { new LightAutomationEnviromentBuilder(_context).WithServiceConfig(Default().Build()).WithMotions(new Dictionary <int, string> { { 500, Detectors.kitchenDetector }, { 501, Detectors.livingRoomDetector }, { 1500, Detectors.hallwayDetectorToilet }, { 1501, Detectors.hallwayDetectorLivingRoom }, //OnNext(Time.Tics(2000), new MotionEnvelope(HallwaylivingRoomDetector)), <- Undetected due motion detectors lag after previous move //OnNext(Time.Tics(2000), new MotionEnvelope(HallwaytoiletDetector)), <- Undetected due motion detectors lag after previous move { 3000, Detectors.livingRoomDetector }, { 3001, Detectors.kitchenDetector } }).Start(); AdvanceJustAfterEnd(); var status = await Query <MotionStatus>(MotionServiceStatusQuery.Create()); var kitchen = await Query <int>(NumberOfPeopleQuery.Create(Detectors.kitchenDetector)); var living = await Query <int>(NumberOfPeopleQuery.Create(Detectors.livingRoomDetector)); kitchen.Should().Be(1); living.Should().Be(1); //Assert.AreEqual(2, status.NumberOfPersonsInHouse); //TODO }
public async Task WhenCrossPassingNumberOfPeopleSlouldBeCorrect() { var(motionEvents, scheduler, lampDictionary) = new LightAutomationServiceBuilder(_context).WithMotion ( OnNext(Time.Tics(500), new MotionEnvelope(Detectors.kitchenDetector)), OnNext(Time.Tics(501), new MotionEnvelope(Detectors.livingRoomDetector)), OnNext(Time.Tics(1500), new MotionEnvelope(Detectors.hallwayDetectorToilet)), OnNext(Time.Tics(1501), new MotionEnvelope(Detectors.hallwayDetectorLivingRoom)), //OnNext(Time.Tics(2000), new MotionEnvelope(HallwaylivingRoomDetector)), <- Undetected due motion detectors lag after previous move //OnNext(Time.Tics(2000), new MotionEnvelope(HallwaytoiletDetector)), <- Undetected due motion detectors lag after previous move OnNext(Time.Tics(3000), new MotionEnvelope(Detectors.livingRoomDetector)), OnNext(Time.Tics(3001), new MotionEnvelope(Detectors.kitchenDetector)) ).Build(); scheduler.AdvanceJustAfterEnd(motionEvents); var status = await _context.Query <MotionStatus>(MotionServiceStatusQuery.Create()); var kitchen = await _context.Query <int>(NumberOfPeopleQuery.Create(Detectors.kitchenDetector)); var living = await _context.Query <int>(NumberOfPeopleQuery.Create(Detectors.livingRoomDetector)); Assert.AreEqual(1, kitchen); Assert.AreEqual(1, living); //Assert.AreEqual(2, status.NumberOfPersonsInHouse); //TODO }
protected MotionStatus Handle(MotionServiceStatusQuery query) { return(new MotionStatus { NumberOfPersonsInHouse = _rooms.Sum(md => md.Value.NumberOfPersonsInArea), NumberOfConfusions = _confusedVectors.Count }); }
protected MotionStatus Handle(MotionServiceStatusQuery query) { return(new MotionStatus { NumberOfPersonsInHouse = _roomService.NumberOfPersons(), NumberOfConfusions = _confusedVectors.Count }); }
public async Task Confusion_NotConfusedVectors_ShouldNotBeConfused() { new LightAutomationEnviromentBuilder(_context).WithServiceConfig(Default().Build()).WithMotions(new Dictionary <int, string> { // First path { 500, Detectors.toiletDetector }, { 1500, Detectors.hallwayDetectorToilet }, { 2000, Detectors.kitchenDetector }, // Second path { 2500, Detectors.livingRoomDetector }, { 3000, Detectors.hallwayDetectorLivingRoom } }).Start(); AdvanceJustAfterEnd(); var status = await Query <MotionStatus>(MotionServiceStatusQuery.Create()); status.NumberOfConfusions.Should().Be(0); LampState(Detectors.kitchenDetector).Should().BeTrue(); }
public async Task MoveInFirstPathShouldNotConfusedNextPathWhenItIsSure() { var(motionEvents, scheduler, lampDictionary) = new LightAutomationServiceBuilder(_context).WithMotion ( // First path OnNext(Time.Tics(500), new MotionEnvelope(Detectors.toiletDetector)), OnNext(Time.Tics(1500), new MotionEnvelope(Detectors.hallwayDetectorToilet)), OnNext(Time.Tics(2000), new MotionEnvelope(Detectors.kitchenDetector)), // Second path OnNext(Time.Tics(2500), new MotionEnvelope(Detectors.livingRoomDetector)), OnNext(Time.Tics(3000), new MotionEnvelope(Detectors.hallwayDetectorLivingRoom)) ).Build(); scheduler.AdvanceJustAfterEnd(motionEvents); var status = await _context.Query <MotionStatus>(MotionServiceStatusQuery.Create()); Assert.AreEqual(0, status.NumberOfConfusions); Assert.AreEqual(true, lampDictionary[Detectors.kitchenDetector].IsTurnedOn); }