Esempio n. 1
0
        public string Transfer(
            Account debitAccount,
            Account creditAccount,
            decimal amount,
            string motif
            )
        {
            MGuid.NewGuid = () => new Guid("64d80a10-4f21-4acb-9d3d-0332e68c4394");

            PexAssume.IsNotNull(debitAccount);
            PexAssume.IsNotNull(creditAccount);
            PexAssume.IsTrue(creditAccount != debitAccount);
            var repository          = new SIRepository();
            var operationRepository = new SIOperationRepository();
            var operationCreator    = new OperationDtoCreator();

            //act
            var operationServices = new OperationServices(operationRepository, repository, operationCreator);

            operationServices.Transfer(debitAccount, creditAccount, amount, motif);

            string result = operationServices.Transfer(debitAccount, creditAccount, amount, motif);

            PexAssert.IsNotNullOrEmpty(result);
            return(result);
        }
Esempio n. 2
0
 public void DateTimeSetTest([PexAssumeUnderTest] XmpTag target, DateTime?value)
 {
     PexAssume.IsNotNull(value);
     target.DateTime = value;
     PexAssert.AreEqual(value.ToString(), target.GetTextNode(XmpTag.XAP_NS, "CreateDate").ToString());
     // TODO: add assertions to method XmpTagTest.DateTimeSetTest(XmpTag, Nullable`1<DateTime>)
 }
Esempio n. 3
0
 public void CreatorSetTest([PexAssumeUnderTest] XmpTag target, string value)
 {
     PexAssume.IsNotNull(value);
     target.Creator = value;
     PexAssert.AreEqual(target.GetCollectionNode(XmpTag.DC_NS, "creator")[0], value);
     // TODO: add assertions to method XmpTagTest.CreatorSetTest(XmpTag, String)
 }
Esempio n. 4
0
        public static PriorityQueue <int> Create(int[] elements)
        {
            PexAssume.IsNotNull(elements);
            PriorityQueue <int> priorityQueue = new PriorityQueue <int>(elements);

            return(priorityQueue);
        }
Esempio n. 5
0
 public void ISOSpeedRatingsSetTest([PexAssumeUnderTest] XmpTag target, uint?value)
 {
     PexAssume.IsNotNull(value);
     target.ISOSpeedRatings = value;
     PexAssert.AreEqual(value.ToString(), target.GetCollectionNode(XmpTag.EXIF_NS, "ISOSpeedRatings")[0].ToString());
     // TODO: add assertions to method XmpTagTest.ISOSpeedRatingsSetTest(XmpTag, Nullable`1<UInt32>)
 }
Esempio n. 6
0
        public void RemoveSettingsPUT1([PexAssumeUnderTest] String[] name, [PexAssumeUnderTest] Object[] value)
        {
            PexAssume.IsTrue(value.Length < 255);
            PexAssume.IsTrue(name.Length == value.Length);
            for (int i = 0; i < value.Length; i++)
            {
                PexAssume.IsTrue(value[i] is String || value[i] is int);
                PexAssume.IsNotNullOrEmpty(name[i]);
                PexAssume.IsNotNull(value[i]);
                //PexAssume.IsTrue(name[i].Contains("t"));
            }

            for (int i = 0; i < name.Length; i++)
            {
                storage.SaveSetting(name[i], value[i]);
            }
            for (int i = 0; i < name.Length; i++)
            {
                if (storage.GetSetting(name[i]) != null)
                {
                    storage.RemoveSetting(name[i]);
                    PexAssert.IsNull(storage.GetSetting(name[i]), name[i] + " not removed");
                }
            }
        }
        public void AddingItemsShouldChangeTheContentHash(string[] toAdd)
        {
            PexAssume.IsNotNull(toAdd);
            PexAssume.AreElementsNotNull(toAdd);
            PexAssume.IsTrue(toAdd.Length > 0);

            (new TestScheduler()).With(sched => {
                var fixture     = new SerializedCollection <ModelTestFixture>();
                var hashes      = new List <Guid>();
                int changeCount = 0;

                fixture.Changed.Subscribe(_ => {
                    hashes.Add(fixture.ContentHash);
                    changeCount++;
                });

                foreach (var v in toAdd)
                {
                    fixture.Add(new ModelTestFixture()
                    {
                        TestString = v
                    });
                    sched.Start();
                }

                PexAssert.AreDistinctValues(hashes.ToArray());
                PexAssert.AreEqual(toAdd.Length, fixture.Count);
                PexAssert.AreEqual(toAdd.Uniq().Count(), changeCount);
            });
        }
    public static int Puzzle(string s)
    {
        PexAssume.IsNotNull(s);
        PexAssume.IsTrue(s.Length > 4);
        if (s.Equals("(())()") | s.Equals("((()))") | s.Equals("()))(("))
        {
            ;                                                          // Pex hint
        }
        int openClose = 0;
        int maxDepth  = 0;

        foreach (char c in s)
        {
            PexAssume.IsTrue(c == ' ' | c == '(' | c == ')' | (c >= 'a' & c <= 'z'));
            if (c == '(')
            {
                openClose++;
                if (openClose > maxDepth)
                {
                    maxDepth = openClose;
                }
            }
            else
            if (c == ')')
            {
                openClose--;
                if (openClose < 0)
                {
                    return(0);
                }
            }
            // else: ignore c
        }
        return((openClose == 0) ? maxDepth : 0);
    }
Esempio n. 9
0
    public string Puzzle(string s, char x)
    {
        PexAssume.IsNotNull(s);
        PexAssume.IsNotNull(x);
        PexAssume.IsTrue(s.Length >= 3);
        int len = s.Length;

        if (s == "codehunt")
        {
            ;
        }
        if (s == "abcabc")
        {
            ;
        }
        for (int i = 0; i < len; i++)
        {
            PexAssume.IsTrue(s[i] == ' ' | (s[i] >= 'a' & s[i] <= 'z'));
        }
        PexAssume.IsTrue(x == ' ' | (x >= 'a' & x <= 'z'));

        int result = global::Program.Puzzle(s, x);

        return(PexSymbolicValue.GetPathConditionString() + " RET_DIV " + PexSymbolicValue.ToString <int>(result));
    }
Esempio n. 10
0
        public decimal ComputeInterestTest(
            [PexAssumeUnderTest] AccountService target,
            Account account,
            double annualRate,
            int months
            )
        {
            var mock = new Mock <Account>();

            mock.SetupSet(m => m.Balance = It.IsInRange(0, 1000, Range.Inclusive));
            mock.SetupSet(m => m.Id      = It.IsInRange(0, 10, Range.Inclusive));

            PexAssume.IsNotNull(account);
            PexAssume.AreEqual(mock.Object, account);
            PexAssume.IsTrue(annualRate > 0);
            PexAssume.IsTrue(annualRate < 1);
            PexAssume.IsTrue(months > 5);
            PexAssume.IsTrue(months <= 12);


            decimal result = target.ComputeInterest(account, annualRate, months);

            return(result);
            // TODO: add assertions to method AccountServiceTest.ComputeInterestTest(AccountService, Account, Double, Int32)
        }
Esempio n. 11
0
        internal double[,] smallSquereMatrix(List <float>[] faceMatrix)
        {
            //tested during loading
            //null
            PexAssume.IsNotNull(faceMatrix);
            //{}
            PexAssume.IsTrue(faceMatrix.Length != 0);
            //{null}
            PexAssume.IsNotNull(faceMatrix[0]);
            //rectangle matrix
            int count = faceMatrix[0].Count;

            PexAssume.IsTrue(faceMatrix.All(x => x != null && count == x.Count));


            object[] args = new object[1];
            args[0] = (object)faceMatrix;
            Type[] parameterTypes = new Type[1];
            parameterTypes[0] = typeof(List <float>).MakeArrayType();
            double[,] result0 = ((MethodBase)(typeof(Program).GetMethod("smallSquereMatrix",
                                                                        BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.NonPublic, (Binder)null,
                                                                        CallingConventions.Standard, parameterTypes, (ParameterModifier[])null)))
                                .Invoke((object)null, args) as double[, ];
            double[,] result = result0;
            return(result);
            // TODO: přidat kontrolní výrazy do: metoda ProgramTest.smallSquertMatrix(List`1<Single>[])
        }
Esempio n. 12
0
        internal void means0(List <float>[] faceMatrix, float[] columnMeans)
        {
            //tested during loading
            //faceMatrix
            //null
            PexAssume.IsNotNull(faceMatrix);
            //{}
            PexAssume.IsTrue(faceMatrix.Length != 0);
            //{null}
            PexAssume.IsNotNull(faceMatrix[0]);
            //rectangle matrix
            int count = faceMatrix[0].Count;

            PexAssume.IsTrue(faceMatrix.All(x => x != null && count == x.Count));

            //columnMeans
            PexAssume.IsNotNull(columnMeans);

            //same count of columns
            PexAssume.IsTrue(faceMatrix[0].Count == columnMeans.Length);


            object[] args = new object[2];
            args[0] = (object)faceMatrix;
            args[1] = (object)columnMeans;
            Type[] parameterTypes = new Type[2];
            parameterTypes[0] = typeof(List <float>).MakeArrayType();
            parameterTypes[1] = typeof(float).MakeArrayType();
            object result = ((MethodBase)(typeof(Program).GetMethod("means0",
                                                                    BindingFlags.DeclaredOnly | BindingFlags.Static | BindingFlags.NonPublic, (Binder)null,
                                                                    CallingConventions.Standard, parameterTypes, (ParameterModifier[])null)))
                            .Invoke((object)null, args);
            // TODO: přidat kontrolní výrazy do: metoda ProgramTest.means0(List`1<Single>[], Single[])
        }
Esempio n. 13
0
 public static global::EmbarkOrders.EmbarkOrder CreateEmbarkOrder(int transporter_i, global::GameState.UnitIndex unit_unitIndex)
 {
     PexAssume.IsNotNull(unit_unitIndex);
     global::EmbarkOrders.EmbarkOrder embarkOrder
         = new global::EmbarkOrders.EmbarkOrder(transporter_i, unit_unitIndex);
     return(embarkOrder);
 }
Esempio n. 14
0
    public string Puzzle(int in_1, string in_2, int in_3)
    {
        PexAssume.IsTrue(in_1 > 1 & in_1 <= 50);
        PexAssume.IsTrue(in_3 > 1 & in_3 <= 50);
        // 12/13/19: Commenting below line to see if it gets rid of FP in cluster 0
        // if (in_1 == 10 || in_1 == 20 || in_1 == 30);

        PexAssume.IsNotNull(in_2);
        PexAssume.IsTrue(in_2.Length >= 3);
        int len = in_2.Length;

        if (in_2 == "codehunt")
        {
            ;
        }
        if (in_2 == "abcabc")
        {
            ;
        }
        for (int x = 0; x < len; x++)
        {
            PexAssume.IsTrue(in_2[x] >= 'a' & in_2[x] <= 'z');
        }


        string result = global::GlobalMembers.Main(in_1, in_2, in_3);

        return(PexSymbolicValue.GetPathConditionString() + " RET_DIV " + PexSymbolicValue.ToString <string>(result));
    }
Esempio n. 15
0
        public string TrimStartWithMax(string input, string startsWith, StringComparison comparisonType, int max)
        {
            PexAssume.IsNotNull(input);
            PexAssume.IsNotNull(startsWith);

            int    count;
            string result = CommonStringExtensions.TrimStart(input, startsWith, comparisonType, max, out count);

            PexAssert.IsNotNull(result);
            PexAssert.IsTrue(result.Length <= input.Length);

            bool isStartsWithNotEmpty = startsWith.Length > 0;

            if (isStartsWithNotEmpty)
            {
                int originalStartsWithCount = CommonStringExtensions.CountSubstringStart(input, startsWith, comparisonType);
                int resultStartsWithCount   = CommonStringExtensions.CountSubstringStart(result, startsWith, comparisonType);

                PexAssert.IsTrue(resultStartsWithCount == 0 ||
                                 resultStartsWithCount == originalStartsWithCount - max);
                PexAssert.IsTrue(originalStartsWithCount - resultStartsWithCount == count);
            }

            return(result);
        }
Esempio n. 16
0
        //check for saved substorage settings removed
        public void SubstorageSettingsPUT2([PexAssumeUnderTest] String subName, [PexAssumeUnderTest] String[] name, [PexAssumeUnderTest] Object[] value)
        {
            PexAssume.IsTrue(name.Length == value.Length);
            for (int i = 0; i < value.Length; i++)
            {
                PexAssume.IsTrue(value[i] is String || value[i] is int);
                PexAssume.IsNotNullOrEmpty(name[i]);
                PexAssume.IsNotNull(value[i]);
                PexAssume.IsTrue(name[i].Contains("t"));
            }
            for (int i = 0; i < name.Length; i++)
            {
                PexAssume.IsNotNullOrEmpty(name[i]);
            }
            ISettingsStorage sub = storage.MakeChildStorage(subName);

            for (int j = 0; j < value.Length; j++)
            {
                sub.SaveSetting(name[j], value[j]);
            }
            for (int j = 0; j < value.Length; j++)
            {
                String curr = name[j];
                sub.RemoveSetting(curr);
                PexAssert.IsNull(sub.GetSetting(curr), curr + " not removed");
            }
        }
Esempio n. 17
0
    // Compute the largest span between any two values in the array
    public static int Puzzle(int[] a)
    {
        PexAssume.IsNotNull(a);
        PexAssume.IsTrue(a.Length >= 2 & a.Length <= 20);
        foreach (int v in a)
        {
            PexAssume.IsTrue(v >= -50 & v <= 50);
        }

        if (a.Length < 2)
        {
            return(0);
        }

        int min = a[0], max = a[0];

        foreach (int v in a)
        {
            if (v < min)
            {
                min = v;
            }
            if (v > max)
            {
                max = v;
            }
        }
        return(max - min);
    }
Esempio n. 18
0
        public void ItemsChangedShouldFire(string[] setters)
        {
            PexAssume.IsNotNull(setters);
            PexAssume.AreElementsNotNull(setters);

            this.Log().InfoFormat("Setting TestString to [{0}]", String.Join(",", setters));

            (new TestScheduler()).With(sched => {
                var output_changed  = new List <object>();
                var output_changing = new List <object>();
                var fixture         = new ModelTestFixture();

                fixture.Changing.Subscribe(output_changing.Add);
                fixture.Changed.Subscribe(output_changed.Add);

                foreach (var v in setters)
                {
                    fixture.TestString = v;
                }

                sched.Start();

                PexAssert.AreEqual(setters.Uniq().Count(), output_changed.Count);
                PexAssert.AreEqual(setters.Uniq().Count(), output_changing.Count);
            });
        }
Esempio n. 19
0
        public void HandleTest(
            [PexAssumeUnderTest] GetPlayerStatisticsHandler target,
            GameDeletedEvent e,
            LookupGamePlayersDto[] lookupGamePlayers,
            GetPlayerStatisticsDto[] getPlayerStatistics
            )
        {
            // assume
            PexAssume.IsNotNull(lookupGamePlayers);
            PexAssume.IsTrue(lookupGamePlayers.Length == 2);
            PexAssume.IsNotNull(lookupGamePlayers[0]);
            PexAssume.IsNotNull(lookupGamePlayers[1]);
            PexAssume.IsNotNull(getPlayerStatistics);
            PexAssume.IsTrue(getPlayerStatistics.Length == 1);
            PexAssume.IsNotNull(getPlayerStatistics[0]);
            PexAssume.IsTrue(lookupGamePlayers[0].PlayerName == getPlayerStatistics[0].PlayerName);

            // arrange
            foreach (var lookupGamePlayer in lookupGamePlayers)
            {
                target.QueryDataStore.Insert <LookupGamePlayersDto>(lookupGamePlayer);
            }
            target.QueryDataStore.Insert <GetPlayerStatisticsDto>(getPlayerStatistics[0]);

            // act
            target.Handle(e);

            // assert
            var playerStats = target.QueryDataStore.GetData <GetPlayerStatisticsDto>().Single();

            PexObserve.ValueAtEndOfTest("playerStats", playerStats);
        }
Esempio n. 20
0
    public static object CreateDisembarkOrder(GameState.UnitIndex idx, HexTiling.HexCoords[] path)
    {
        PexAssume.IsNotNull(idx);
        PexAssume.IsNotNull(path);
        PexAssume.AreElementsNotNull(path);

        return(EmbarkOrders.DisembarkOrder.NewDisembark(idx, ListModule.OfArray(path)));
    }
Esempio n. 21
0
 public void KeywordsSetTest([PexAssumeUnderTest] XmpTag target, string[] value)
 {
     PexAssume.IsNotNull(value);
     PexAssume.IsTrue(!value.Contains(null));
     target.Keywords = value;
     PexAssert.IsTrue(value.SequenceEqual(target.GetCollectionNode(XmpTag.DC_NS, "subject")));
     // TODO: add assertions to method XmpTagTest.KeywordsSetTest(XmpTag, String[])
 }
Esempio n. 22
0
        /// Summary
        /// Time: 1 min 46 sec
        /// Pattern: Constructor Test, State Relation
        /// Combines two tests into a single test
        public void ToArrayTest([PexAssumeUnderTest] int[] expected)
        {
            PexAssume.IsNotNull(expected);
            SinglyLinkedList <int> sll = new SinglyLinkedList <int>(expected);

            CollectionAssert.AreEqual(expected, sll.ToArray());
            PexAssert.AreEqual(expected.Length, sll.ToArray().Length);
        }
Esempio n. 23
0
 public void addTest(
     [PexAssumeUnderTest] ArrayList target,
     object item,
     int position
     )
 {
     PexAssume.IsNotNull(target);
     target.add(item, position);
 }
Esempio n. 24
0
        public int op_ImplicitTest01(Delay delay)
        {
            PexAssume.IsNotNull(delay);

            int result = (int)delay;

            return(result);
            // TODO: add assertions to method DelayTest.op_ImplicitTest01(Delay)
        }
 private TreeDictionary <TKey, TValue, DefaultComparer <TKey> > CreateDictionary <TKey, TValue>(
     TKey[] keys, TValue[] values) where TKey : struct
 {
     PexAssume.IsNotNull(keys);
     PexAssume.IsNotNull(values);
     PexAssume.AreEqual(keys.Length, values.Length);
     PexAssume.AreDistinctValues(keys);
     return(TreeDictionary.Empty <TKey, TValue>().AddAll(keys.Zip(values)));
 }
Esempio n. 26
0
        public void FNumberSetTest([PexAssumeUnderTest] XmpTag target, double value)
        {
            PexAssume.IsNotNull(value);
            target.FNumber = value;
            double result = target.GetRationalNode(XmpTag.EXIF_NS, "FNumber").Value;

            PexAssert.AreEqual(value, result, 0.001);
            // TODO: add assertions to method XmpTagTest.FNumberSetTest(XmpTag, Nullable`1<Double>)
        }
Esempio n. 27
0
        public static FSharpOption <global::GameState.PlayerId> Create(global::GameState.PlayerId value_playerId)
        {
            PexAssume.IsNotNull(value_playerId);

            FSharpOption <global::GameState.PlayerId> fSharpOption
                = new FSharpOption <global::GameState.PlayerId>(value_playerId);

            return(fSharpOption);
        }
Esempio n. 28
0
        public void HeapSortWorks(int[] values)
        {
            PexAssume.IsNotNull(values);

            var result = HeapSort(values).ToArray();

            PexObserve.ValueForViewing("sorted", result);
            Assert.That(result, Is.Ordered);
        }
Esempio n. 29
0
        //[PexMethod]
        public void TestClearRoutinesPUT1([PexAssumeUnderTest] String[] name, Object[] value, [PexAssumeUnderTest] String[] key)
        {
            //PexAssume.IsNotNull(mainKey);
            PexAssume.IsNotNull(value);
            PexAssume.IsTrue(key.Length >= 1);
            PexAssume.IsTrue(key.Length <= name.Length);
            PexAssume.IsTrue(name.Length == value.Length);

            for (int i = 0; i < name.Length; i++)
            {
                PexAssume.IsNotNullOrEmpty(name[i]);
                PexAssume.IsTrue(value[i] is String || value[i] is int);
                PexAssume.IsNotNull(value[i]);
                if (i < key.Length)
                {
                    PexAssume.IsNotNull(key[i]);
                }
            }

            for (int i = 0; i < value.Length - key.Length; i++)
            {
                PexAssume.IsNotNull(value[i + key.Length]);
                PexAssume.IsNotNull(name[i + key.Length]);
            }

            /* for (int i = 0; i < key.Length; i++)
             * {
             *
             * }*/
            NUnitRegistry.TestMode = true;
            using (RegistryKey mainKey = NUnitRegistry.CurrentUser){
                mainKey.SetValue(name[0], value[0]);
                int k = 0;
                for (k = 1; k < key.Length; k++)
                {
                    RegistryKey subKey = mainKey.CreateSubKey(key[k - 1]);
                    subKey.SetValue(name[k], value[k]);
                }
                k = 0;
                for (int i = 0; i < value.Length - key.Length; i++)
                {
                    RegistryKey subKey = mainKey.CreateSubKey(key[k]);
                    subKey.SetValue(name[i + key.Length], value[i + key.Length]);
                    k++;
                    if (k == key.Length)
                    {
                        k = 0;
                    }
                    //PexAssume.IsNotNull(value[i + key.Length]);
                    //PexAssume.IsNotNull(key[i + key.Length]);
                }
                NUnitRegistry.ClearTestKeys();
                PexAssert.IsTrue(mainKey.ValueCount == 0);
                PexAssert.IsTrue(mainKey.SubKeyCount == 0);
            }
        }
Esempio n. 30
0
        public void Ctor_WhenCalledWithValues_ResultingCountIsEqualToValuesCount <TPriority, TValue>(
            KeyValuePair <TPriority, TValue>[] values)
        {
            PexAssume.IsNotNull(values);
            var initialValuesCount = values.Count();

            var heap = new BinaryHeap <TPriority, TValue>(values);

            Assert.That(heap.Count, Is.EqualTo(initialValuesCount));
        }