Exemplo n.º 1
0
        private string GetRandomDef()
        {
            const string DEFS = "PAL";
            char         ch   = DEFS[FRandom.Next(DEFS.Count())];

            return(ch.ToString(CultureInfo.InvariantCulture));
        }
Exemplo n.º 2
0
        private AwsExceptionFilterPoco CreateFilter(bool incStudent)
        {
            Shuffle(FRegisters);

            Register r            = FindRegisterWithStudentMarks();
            int      studentIndex = FRandom.Next(0, r.StudentMarks.Count);

            AwsExceptionFilterPoco result = new AwsExceptionFilterPoco();

            if (incStudent)
            {
                result.StudentId = r.StudentMarks[studentIndex].StudentId;
            }

            result.StartDateTime = GetRandomStartDate();
            result.EndDateTime   = result.StartDateTime.AddDays(FRandom.Next(1, 4));

            result.Types[(int)AttExceptionType.CetExceptionAdd]            = true;
            result.Types[(int)AttExceptionType.CetExceptionRemove]         = true;
            result.Types[(int)AttExceptionType.CetExceptionWithdraw]       = true;
            result.Types[(int)AttExceptionType.CetExceptionCancelWithdraw] = true;
            result.Types[(int)AttExceptionType.CetExtendedAbsence]         = true;
            result.Types[(int)AttExceptionType.CetWithdrawFromCollege]     = true;

            if (result == null)
            {
                throw new Exception("Could not create exception filter!");
            }

            return(result);
        }
Exemplo n.º 3
0
        private AwsLedgerFilterPoco CreateLedgerFilter()
        {
            AwsLedgerFilterPoco result = null;

            Shuffle(FRegisters);

            foreach (var reg in FRegisters)
            {
                if (reg.StudentMarks != null && reg.StudentMarks.Count > 0)
                {
                    int studentIndex = FRandom.Next(0, reg.StudentMarks.Count);

                    result = new AwsLedgerFilterPoco()
                    {
                        StudentId = reg.StudentMarks[studentIndex].StudentId,
                        EventId   = reg.EventId,
                        Week      = reg.Week
                    };

                    break;
                }
            }

            if (result == null)
            {
                throw new Exception("Could not create student ledger filter!");
            }

            return(result);
        }
Exemplo n.º 4
0
        public void Random3()
        {
            var random = FRandom.SeedDefault();

            Assert.AreEqual(2, FRandom.Next(random, 0, 5).Number);
            Assert.AreEqual(2, FRandom.Next(random, 0, 5).Number);
            Assert.AreEqual(2, FRandom.Next(random, 0, 5).Number);
        }
        public void HappyCase()
        {
            var a = Collisions.CollisionFuntions.ElectrostaticRepulsion(new Particles.Proton(10), new Particles.Proton(10),
                                                                        FRandom.Seed(1, 1), new Vector3D(1, 1, 1), new Vector3D(1, -1, -1));

            Assert.AreEqual(new Vector3D(0, 2, 2), a.Item1.Position);
            Assert.AreEqual(new Vector3D(-0, -2, -2), a.Item2.Position);
            Assert.AreEqual("2.4258631722889", Convert.ToString(a.Item1.Velocity));
            Assert.AreEqual("2.4258631722889", Convert.ToString(a.Item2.Velocity));
        }
Exemplo n.º 6
0
        public void HappyCase()
        {
            //Testing to make sure deterministic randomness
            var a = Collisions.CollisionFuntions.RandomiseVelocity(FRandom.Seed(1, 1));

            Assert.AreEqual(2822, a.Number);
            var b = Collisions.CollisionFuntions.RandomiseVelocity(FRandom.Seed(1, 1));

            Assert.AreEqual(2822, b.Number);
        }
Exemplo n.º 7
0
        public void TestNextFixed()
        {
            var r = new FRandom(1);

            var a = r.NextFixed();

            Assert.AreEqual(new Fixed(995757), a);

            var b = r.NextFixed(Fixed.FromFraction(-102324, 1000), Fixed.FromFraction(12034, 100));

            Assert.AreEqual(new Fixed(-16118036), b);
        }
Exemplo n.º 8
0
        public void TestNext()
        {
            var r = new FRandom(1);

            var a = r.Next(107562);

            Assert.AreEqual(78325, a);

            var b = r.Next(-102324, 12034);

            Assert.AreEqual(-28803, b);
        }
Exemplo n.º 9
0
        protected override async Task TestPutAtRoot()
        {
            if (FNewlyInsertedOLAMarks.Count > 0)
            {
                var m = FNewlyInsertedOLAMarks[0];
                m.Session = FRandom.Next();

                Uri uri      = new Uri(FBaseUri, "OLAStaging");
                var response = await FClient.PutAsJsonAsync(uri.ToString(), m);
                await CheckStatusCodeIs(response, HttpStatusCode.MethodNotAllowed);
            }
        }
Exemplo n.º 10
0
 public void EdgeCase()
 {
     //Checkes to make sure the randomiser only produces numbers within the boundries.
     for (int i = 0; i < 100; i++)
     {
         if (Collisions.CollisionFuntions.RandomiseVelocity(FRandom.Seed(1, 1)).Number > 2.9E8 ||
             Collisions.CollisionFuntions.RandomiseVelocity(FRandom.Seed(1, 1)).Number < 1E3)
         {
             Assert.Fail();
         }
     }
     Assert.IsTrue(1 == 1);
 }
Exemplo n.º 11
0
        public void RandomSkip()
        {
            var random = FRandom.SeedDefault();
            var sb     = new StringBuilder();

            for (int i = 0; i < 10; i++)
            {
                var result = FRandom.Skip(i, random, 0, 10);
                sb.Append(result.Number).Append(" ");
            }
            string gen1Results = sb.ToString();

            Assert.AreEqual("5 1 2 2 8 0 2 7 9 0 ", gen1Results);
        }
Exemplo n.º 12
0
        public void Random2()
        {
            var random = FRandom.Seed(3, 7);
            var sb     = new StringBuilder();

            for (int i = 0; i < 10; i++)
            {
                random = FRandom.Next(random, 0, 10);
                sb.Append(random.Number).Append(" ");
            }
            string gen1Results = sb.ToString();

            Assert.AreEqual("6 1 2 8 4 2 5 1 3 6 ", gen1Results);
        }
Exemplo n.º 13
0
        protected override async Task TestPost()
        {
            FNewlyInsertedExceptions = new List <ExceptionMark>();

            int numIters = FRandom.Next(4, 10);

            for (int i = 0; i < numIters; ++i)
            {
                int markId = GetMarkId();

                var em = new ExceptionMark
                {
                    ExceptionType     = AttExceptionType.CetExtendedAbsence,
                    MarkId            = markId,
                    Comments          = GetRandomString(FRandom.Next(1, 129), true),
                    StudentExceptions = new List <StudentException>(),
                    Modified          = true
                };

                em.StartDateTime = GetRandomStartDate();
                em.EndDateTime   = em.StartDateTime.AddDays(FRandom.Next(1, 60));

                int        numStudents  = FRandom.Next(1, 6);
                List <int> studentsUsed = new List <int>();
                for (int n = 0; n < numStudents; ++n)
                {
                    int studentId = GetRandomStudentId();
                    if (!studentsUsed.Contains(studentId))
                    {
                        em.StudentExceptions.Add(new StudentException
                        {
                            StudentId = studentId,
                            Modified  = true
                        });

                        studentsUsed.Add(studentId);
                    }
                }

                Uri uri      = new Uri(FBaseUri, "StudentExceptions");
                var response = await FClient.PostAsJsonAsync(uri.ToString(), em);
                await CheckStatusCodeIs(response, HttpStatusCode.Created);

                var se = await response.Content.ReadAsAsync <ExceptionMark>();

                se.CheckSameValues(em);

                FNewlyInsertedExceptions.Add(se);
            }
        }
Exemplo n.º 14
0
        protected override async Task TestPut()
        {
            // make changes to the newly added defs...

            foreach (var md in FNewlyInsertedOLAMarks)
            {
                // change session...
                md.Session = FRandom.Next();

                Uri uri      = new Uri(FBaseUri, string.Format("OLAStaging/{0}", md.Id));
                var response = await FClient.PutAsJsonAsync(uri.ToString(), md);
                await CheckSuccessStatusCode(response);

                var mdRetVal = await response.Content.ReadAsAsync <OlaMark>();

                md.CheckSameValues(mdRetVal);
            }
        }
Exemplo n.º 15
0
        protected override async Task TestPost()
        {
            FNewlyInsertedDefinitions = new List <MarkDefinition>();

            Uri uri = new Uri(FBaseUri, "MarkDefinitions");

            int numIters = FRandom.Next(4, 10);

            for (int n = 0; n < numIters; ++n)
            {
                string notifyText = GetRandomStringOrEmpty(FRandom.Next(10, 255), true);

                var newDefn = new MarkDefinition
                {
                    Abbreviation = GetUniqueAbbreviation(),
                    Name         = GetUniqueName(),
                    Card         = false,
                    Colour       = GetRandomColour(),
                    Definition   = GetRandomDef(),
                    Description  = GetRandomStringOrEmpty(FRandom.Next(10, 128), true),
                    Notification = notifyText,
                    Notify       = !string.IsNullOrWhiteSpace(notifyText),
                    OriginId     = null,
                    OriginalId   = string.Empty,
                    Precedence   = false,
                    ShortcutKey  = GetUniqueShortcutKey()
                };

                var response = await FClient.PostAsJsonAsync(uri.ToString(), newDefn);
                await CheckStatusCodeIs(response, HttpStatusCode.Created);

                var md = await response.Content.ReadAsAsync <MarkDefinition>();

                md.CheckSameValues(newDefn);

                FNewlyInsertedDefinitions.Add(md);
            }
        }
Exemplo n.º 16
0
        [TestMethod] //Very crude test to check that there is an approximately even distribution of 0, 1 results
        public void RandomSeedFromClock()
        {
            var random = FRandom.SeedFromClock(DateTime.Now);
            int zeros  = 0;
            int ones   = 0;

            for (int i = 0; i < 1000; i++)
            {
                random = FRandom.Next(random, 0, 2);
                if (random.Number == 0)
                {
                    zeros += 1;
                }
                else
                {
                    ones += 1;
                }
            }

            Assert.AreEqual(1000, zeros + ones);
            Assert.IsTrue(zeros < 550);
            Assert.IsTrue(ones < 550);
        }
Exemplo n.º 17
0
        public void HappyCase()
        {
            var a = Collisions.CollisionFuntions.GenerateParticleWithRandomVelocity(new Particles.Proton(0), FRandom.Seed(1, 1));

            Assert.AreEqual(new Particles.Proton(0).GetType(), a.GetType());
            Assert.AreEqual(2822, a.Velocity);
        }
Exemplo n.º 18
0
 public static Particle GenerateParticleWithRandomVelocity <T>(T particle, FRandom rand) where T : Particle
 {
     return((T)Activator.CreateInstance(particle.GetType(), RandomiseVelocity(rand).Number, particle.Position, particle.Distance));
 }
Exemplo n.º 19
0
 private DateTime GetRandomStartDate()
 {
     return(FSomeRegisterDates[FRandom.Next(0, FSomeRegisterDates.Length)].Date);
 }
Exemplo n.º 20
0
        public void EdgeCase()
        {
            var a = Collisions.CollisionFuntions.PairProductionPhoton(new Particles.Photon(1, 1E100), FRandom.Seed(1, 1));

            Assert.AreEqual(new Particles.Proton(0).GetType(), a.Item1.GetType());
            var b = Collisions.CollisionFuntions.PairProductionPhoton(new Particles.Photon(1, 1E-100), FRandom.Seed(1, 1));

            Assert.AreEqual(new Particles.Electron(0).GetType(), b.Item1.GetType());
        }
        public void HappyCase()
        {
            var a = Collisions.VectorFunctions.SingularEjection(new Particles.Proton(0), FRandom.Seed(1, 1));

            Assert.AreEqual(new Vector3D(203, 11, 132), a.Position);

            var b = Collisions.VectorFunctions.SingularEjection(new Particles.Photon(), FRandom.Seed(1, 1));

            Assert.AreEqual(new Vector3D(203, 11, 132), b.Position);

            var c = Collisions.VectorFunctions.SingularEjection(new Particles.Proton(0), FRandom.Seed(38, 192));

            Assert.AreEqual(new Vector3D(157, -11, 124), c.Position);

            var d = Collisions.VectorFunctions.SingularEjection(new Particles.Photon(), FRandom.Seed(112, 6));

            Assert.AreEqual(new Vector3D(64, -57, 7), d.Position);
        }
Exemplo n.º 22
0
 private string GetUniqueName()
 {
     return(GetUniqueString(FRandom.Next(2, 10), true, FExistingDefinitions.Select(x => x.Name).Union(FNewlyInsertedDefinitions.Select(x => x.Name))));
 }
Exemplo n.º 23
0
        public void HappyCase()
        {
            var a = Collisions.CollisionFuntions.Annialation(new Particles.Proton(10000), new Particles.Antiproton(55560), FRandom.Seed(1, 1));

            Assert.AreEqual("6.60639434893911E-16", Convert.ToString(a.Item1.Wavelength));
            Assert.AreEqual("4.54105498634328E+23", Convert.ToString(a.Item1.Frequency));
            Assert.AreEqual(new Particles.Photon().GetType(), a.Item1.GetType());
            Assert.AreEqual(new Particles.Photon().GetType(), a.Item2.GetType());
        }
        public void HappyCase()
        {
            var Outputs1 = Collisions.CollisionFuntions.ElectronCaputre(Collisions.CollisionFuntions.AtomCreator(8, 16), FRandom.Seed(1, 1));

            Assert.AreEqual("Nitrogen", Outputs1.Item1.Name);
            Assert.AreEqual(7, Outputs1.Item1.AtomicNumber);
            Assert.AreEqual(16, Outputs1.Item1.MassNumber);
            Assert.AreEqual("Electron-Neutrino", Outputs1.Item2.Name);
            var Outputs2 = Collisions.CollisionFuntions.ElectronCaputre(Collisions.CollisionFuntions.AtomCreator(95, 240), FRandom.Seed(1, 1));

            Assert.AreEqual("Plutonium", Outputs2.Item1.Name);
            Assert.AreEqual(94, Outputs2.Item1.AtomicNumber);
            Assert.AreEqual(240, Outputs2.Item1.MassNumber);
            Assert.AreEqual("Electron-Neutrino", Outputs1.Item2.Name);
            var Outputs3 = Collisions.CollisionFuntions.ElectronCaputre(Collisions.CollisionFuntions.AtomCreator(36, 84), FRandom.Seed(1, 1));

            Assert.AreEqual("Bromine", Outputs3.Item1.Name);
            Assert.AreEqual(35, Outputs3.Item1.AtomicNumber);
            Assert.AreEqual(84, Outputs3.Item1.MassNumber);
            Assert.AreEqual("Electron-Neutrino", Outputs1.Item2.Name);
        }
Exemplo n.º 25
0
 private string GetUniqueAbbreviation()
 {
     return(GetUniqueString(FRandom.Next(2, 10), false, FExistingDefinitions.Select(x => x.Abbreviation).Union(FNewlyInsertedDefinitions.Select(x => x.Name))));
 }
        public void HappyCase()
        {
            var a = Collisions.VectorFunctions.OppositeEjections(new Particles.Proton(0), new Particles.Proton(0), FRandom.Seed(1, 1));

            Assert.AreEqual(new Vector3D(203, 11, 132), a.Item1.Position);
            Assert.AreEqual(new Vector3D(-203, -11, -132), a.Item2.Position);

            var b = Collisions.VectorFunctions.OppositeEjections(new Particles.Photon(), new Particles.Photon(), FRandom.Seed(1, 1));

            Assert.AreEqual(new Vector3D(203, 11, 132), b.Item1.Position);
            Assert.AreEqual(new Vector3D(-203, -11, -132), b.Item2.Position);

            var c = Collisions.VectorFunctions.OppositeEjections(new Particles.Proton(0), new Particles.Proton(0), FRandom.Seed(38, 192));

            Assert.AreEqual(new Vector3D(157, -11, 124), c.Item1.Position);
            Assert.AreEqual(new Vector3D(-157, 11, -124), c.Item2.Position);

            var d = Collisions.VectorFunctions.OppositeEjections(new Particles.Photon(), new Particles.Photon(), FRandom.Seed(112, 6));

            Assert.AreEqual(new Vector3D(64, -57, 7), d.Item1.Position);
            Assert.AreEqual(new Vector3D(-64, 57, -7), d.Item2.Position);
        }
Exemplo n.º 27
0
 public static FList <Particles.Particle> GenerateListOfParticlesWithRandomVelocity <T>(T particle, int numberOfInputParticles, FRandom Rand) where T : Particle
 {
     return(numberOfInputParticles != 1 ? FList.New(GenerateParticleWithRandomVelocity(particle, Rand), GenerateListOfParticlesWithRandomVelocity(GenerateParticleWithRandomVelocity(particle, FRandom.Next(Rand, 0, 100)), numberOfInputParticles - 1, FRandom.Next(Rand, 0, 100))) : FList.New(GenerateParticleWithRandomVelocity(particle, Rand)));
 }
Exemplo n.º 28
0
 public static FRandom RandomiseVelocity(FRandom Rand)
 {
     return(FRandom.Next(Rand, Convert.ToInt32(Math.Pow(1, 3)), Convert.ToInt32(Math.Pow(2.9, 8))));
 }
        public void Edgecase_WIP()
        {
            var Outputs = Collisions.CollisionFuntions.ElectronCaputre(Collisions.CollisionFuntions.AtomCreator(1, 1), FRandom.Seed(1, 1));

            Assert.AreEqual(1, Outputs.Item1.MassNumber);
            Assert.AreEqual(0, Outputs.Item1.AtomicNumber);
            var Outputs2 = Collisions.CollisionFuntions.ElectronCaputre(Collisions.CollisionFuntions.AtomCreator(118, 293), FRandom.Seed(1, 1));

            Assert.AreEqual("Tennessine", Outputs2.Item1.Name);
            Assert.AreEqual(117, Outputs2.Item1.AtomicNumber);
            Assert.AreEqual(293, Outputs2.Item1.MassNumber);
        }
        public void HappyCase()
        {
            var a = Collisions.CollisionFuntions.VelocitySelector(new Particles.Proton(0), 100, 4500, 1, FRandom.Seed(1, 1));

            Assert.AreEqual(19, FList.Length(a));

            var b = Collisions.CollisionFuntions.VelocitySelector(new Particles.Electron(0), 100, 4500, 1, FRandom.Seed(1, 1));

            Assert.AreEqual(19, FList.Length(b));

            var c = Collisions.CollisionFuntions.VelocitySelector(new Particles.Proton(0), 100, 4500, 1, FRandom.Seed(35, 73));

            Assert.AreEqual(17, FList.Length(c));

            var d = Collisions.CollisionFuntions.VelocitySelector(new Particles.Electron(0), 100, 4000, 1, FRandom.Seed(1, 1));

            Assert.AreEqual(14, FList.Length(d));
        }