public void ShouldThrowExceptionForMalformedData()
        {

            var enterDateTime = DateTime.Now;
            var exitDateTime = enterDateTime.AddDays(1);

            var resultTimeSpan = exitDateTime.Subtract(enterDateTime);

            var stat = new LocationStats
            {
                Entries = new List<LocationStatsEntry>
                                             {
                                                 new LocationStatsEntry
                                                     {
                                                         Date = enterDateTime,
                                                         Kind = LocationStatsEntry.EntryKind.Exit
                                                     },
                                                     new LocationStatsEntry
                                                     {
                                                         Date = exitDateTime,
                                                         Kind = LocationStatsEntry.EntryKind.Enter
                                                     }
                                             }
            };

            Assert.That(() => stat.GetTotalTimeSpent(), Throws.Exception.TypeOf<InvalidOperationException>());
            

        }
        public void ShouldReturnCorrectSpentTime()
        {

            var enterDateTime = DateTime.Now;
            var exitDateTime = enterDateTime.AddDays(1);

            var resultTimeSpan= exitDateTime.Subtract(enterDateTime);

            var stat = new LocationStats
                           {
                               Entries = new List<LocationStatsEntry>
                                             {
                                                 new LocationStatsEntry
                                                     {
                                                         Date = enterDateTime,
                                                         Kind = LocationStatsEntry.EntryKind.Enter
                                                     },
                                                 new LocationStatsEntry
                                                     {
                                                         Date = exitDateTime,
                                                         Kind = LocationStatsEntry.EntryKind.Exit
                                                     }
                                             }
                           };

            Assert.AreEqual(resultTimeSpan,stat.GetTotalTimeSpent());

        }
        public void ShouldReturnZeroTimespanForNoEntry()
        {
            var stat = new LocationStats
                           {
                               Entries = new List<LocationStatsEntry>()
                           };

            Assert.That(()=>stat.GetTotalTimeSpent(),Is.EqualTo(TimeSpan.Zero));
        }
Пример #4
0
    void Start()
    {
        if (LOC_STAT_SOLDIER == null)
        {
            LOC_STAT_SOLDIER = new List<int>();
            for (int i = 0; i < 40; i++)
                LOC_STAT_SOLDIER.Add(0);
            LOC_STAT_OBSTACLE = new List<int>();
            for (int i = 0; i < 40; i++)
                LOC_STAT_OBSTACLE.Add(0);
            LOC_STAT_BOULDER = new List<int>();
            for (int i = 0; i < 40; i++)
                LOC_STAT_BOULDER.Add(0);
        }

        startLocation = this.transform.position;
        offset = 0;
        RB_activated = false;
        pushed = false;

        if (CurrentGameState.FirstTime)
        {
            LocationStats ls = new LocationStats { Boulder = 0, Soldier = 0, Obstacle = 0 };
            int modifier = (layer > 5) ? 2 : 1;

            int sum = difficulty_soldier + difficulty_obstacles + difficulty_catapults;
            int lsSum = 0;

            while (lsSum > sum + modifier || lsSum < sum - modifier)
            {
                ls.Soldier = Mathf.Min(difficulty_soldier + Random.Range(-modifier, modifier + 1), 10);
                ls.Boulder = Mathf.Min(difficulty_catapults + Random.Range(-modifier, modifier + 1), 10);
                ls.Obstacle = Mathf.Min(difficulty_obstacles + Random.Range(-modifier, modifier + 1), 10);

                lsSum = ls.Soldier + ls.Boulder + ls.Obstacle;
            }

            LOC_STAT_SOLDIER[levelID] = ls.Soldier;
            LOC_STAT_OBSTACLE[levelID] = ls.Obstacle;
            LOC_STAT_BOULDER[levelID] = ls.Boulder;
            //LOC_STATS.Insert(levelID, ls);
        }

        difficulty_soldier = LOC_STAT_SOLDIER[levelID];
        difficulty_obstacles = LOC_STAT_OBSTACLE[levelID];
        difficulty_catapults = LOC_STAT_BOULDER[levelID];

        if (CurrentGameState.JustStarted && levelID == 0)
        {
            CurrentGameState.JustStarted = false;
            CurrentGameState.locID = this.levelID;
            CurrentGameState.previousPosition = this.transform.position;
            CurrentGameState.previousPreviousPosition = this.transform.position;
            CurrentGameState.completedLevelLocations.Add(this.transform.position);
        }
        if (CurrentGameState.locID == this.levelID)
        {
            CurrentGameState.loc = this;
            GameObject lr;
            linerenderes = new GameObject[locations.Length];
            for (int i = 0; i < locations.Length; i++)
            {
                lr = new GameObject();
                lr.AddComponent<LineRenderer>();
                SetupLineRenderer(lr.GetComponent<LineRenderer>(), locations[i]);
                linerenderes[i] = lr;
            }
        }
        else
        {
            linerenderes = new GameObject[0];
        }
        if (CurrentGameState.completedlevels.Contains(this.levelID))
        {
            if (CurrentGameState.loc != this)
                ActivateRigidBody();
        }
        else
        {
            this.GetComponent<CapsuleCollider>().enabled = false;
            foreach (MeshRenderer mr in this.GetComponentsInChildren<MeshRenderer>())
                mr.enabled = false;
        }
    }
Пример #5
0
        private void InsertOrUpdateLocationStats(DateTime now, Domain.Location.Location loc, LocationStatsEntry.EntryKind entryKind)
        {
            var persistedStat = (from l in _locationStats.All()
                                 where l.Location.Id == loc.Id
                                 select l).FirstOrDefault();

            if (persistedStat != null)
            {
                persistedStat.Entries.Add(new LocationStatsEntry { Date = now, Kind = entryKind });


                lock (_locationStats)
                {
                    _locationStats.Update(persistedStat);    
                }
                
            }
            else
            {
                persistedStat = new LocationStats
                                    {
                                        Entries = new List<LocationStatsEntry>
                                                      {
                                                          new LocationStatsEntry
                                                              {
                                                                  Date = now,
                                                                  Kind = entryKind
                                                              }
                                                      },
                                        Location = loc
                                    };
                lock(_locationStats){
                    _locationStats.Add(persistedStat);
                }
            }
        }