public void ContentsAreStoredCorrectly()
            {
                var array    = new[] { "f", "g", "h", "i", "j" };
                var contents = string.Join(System.Environment.NewLine, array);
                var tmpFile  = System.IO.Path.Combine(this.GetMethodSpecificWorkingDirectory(), PFW.CSIST203.Project1.Functions.ArrayFunctions.DefaultPersistentFile);

                PFW.CSIST203.Project1.Functions.ArrayFunctions obj = new PFW.CSIST203.Project1.Functions.ArrayFunctions(tmpFile);
                obj.Store(array);

                // read the contents of the stored file back
                var savedContents = string.Empty;

                AssertDelegateSuccess(() =>
                {
                    using (System.IO.Stream stream = System.IO.File.OpenRead(tmpFile))
                    {
                        using (System.IO.StreamReader reader = new System.IO.StreamReader(stream))
                        {
                            savedContents = reader.ReadToEnd().Trim();
                        }
                    }
                }, "The file handle should have been Dispose()'d of when the ArrayFunctions class finishes storing the data");

                Assert.AreEqual(contents, savedContents, "The saved contents needs to match the expected contents");
            }
            public void FileDoesNotExist()
            {
                var directory = this.GetMethodSpecificWorkingDirectory();

                PFW.CSIST203.Project1.Functions.ArrayFunctions obj = new PFW.CSIST203.Project1.Functions.ArrayFunctions();
                AssertDelegateFailure(() =>
                {
                    obj.Load(5);
                }, typeof(System.IO.FileNotFoundException), "The data file should not have been present for this test and loading from it should have failed");
            }
 public void Parameterless()
 {
     PFW.CSIST203.Project1.Functions.ArrayFunctions obj = null;
     AssertDelegateSuccess(() =>
     {
         obj = new Project1.Functions.ArrayFunctions();
     }, "Failed to instantiate object correctly using default constructor");
     Assert.IsNotNull(obj, "This object cannot be null");
     Assert.AreEqual(PFW.CSIST203.Project1.Functions.ArrayFunctions.DefaultPersistentFile, obj.PersistentFile);
     Assert.IsNotNull(obj.Randomizer);
 }
            public void AllParameters()
            {
                string path = System.IO.Path.GetTempFileName();

                PFW.CSIST203.Project1.Functions.ArrayFunctions obj = null;
                AssertDelegateSuccess(() =>
                {
                    obj = new Project1.Functions.ArrayFunctions(path, 123);
                }, "Failed to instantiate object correctly using default constructor");
                Assert.IsNotNull(obj, "This object cannot be null");
                Assert.AreEqual(path, obj.PersistentFile);
                Assert.IsNotNull(obj.Randomizer);
            }
            public void ShiftsCorrectly()
            {
                PFW.CSIST203.Project1.Functions.ArrayFunctions obj = new PFW.CSIST203.Project1.Functions.ArrayFunctions();
                var startingArray = new[] { "a", "b", "c", "d", "e" };
                var shift1        = new[] { "b", "c", "d", "e", "a" };
                var result1       = obj.ShiftLeft(startingArray);

                Assert.IsTrue(ArraysMatch(result1, shift1), "The shifted array element alignment did Not match the expected result");
                var shift2  = new[] { "c", "d", "e", "a", "b" };
                var result2 = obj.ShiftLeft(obj.ShiftLeft(startingArray));

                Assert.IsTrue(ArraysMatch(result2, shift2), "The shifted array element alignment did Not match the expected result");
            }
            public void ReversesCorrectly()
            {
                PFW.CSIST203.Project1.Functions.ArrayFunctions obj = new PFW.CSIST203.Project1.Functions.ArrayFunctions();
                var startingArray = new[] { "a", "b", "c", "d", "e" };
                var reversal      = new[] { "e", "d", "c", "b", "a" };

                startingArray = obj.Reverse(startingArray);
                Assert.IsTrue(ArraysMatch(startingArray, reversal));
                startingArray = obj.Reverse(startingArray);
                startingArray = obj.Reverse(startingArray);
                Assert.IsTrue(ArraysMatch(startingArray, reversal));
                startingArray = obj.Reverse(startingArray);
                reversal      = obj.Reverse(reversal);
                Assert.IsTrue(ArraysMatch(startingArray, reversal));
            }
            public void RandomizesCorrectly()
            {
                PFW.CSIST203.Project1.Functions.ArrayFunctions obj = new PFW.CSIST203.Project1.Functions.ArrayFunctions(PFW.CSIST203.Project1.Functions.ArrayFunctions.DefaultPersistentFile, 123);
                var startingArray = new[] { "a", "b", "c", "d", "e" };
                var random1       = new[] { "e", "c", "d", "b", "a" };

                startingArray = obj.Randomize(startingArray);
                Assert.IsTrue(ArraysMatch(startingArray, random1), "The first randomization did not result in the expected result");
                // reset the array back
                startingArray = new[] { "a", "b", "c", "d", "e" };
                Random rnd = new Random(123);
                var    manualRandomizer = startingArray.OrderBy(n => rnd.Next()).ToArray();

                Assert.IsTrue(ArraysMatch(random1, manualRandomizer), "The encapsulated randomization did not match the external implementation expectation");
            }
            public void ContentsAreLoadedCorrectly()
            {
                var array    = new[] { "a", "b", "c", "d", "e" };
                var contents = string.Join(System.Environment.NewLine, array);
                var tmpFile  = System.IO.Path.Combine(this.GetMethodSpecificWorkingDirectory(), PFW.CSIST203.Project1.Functions.ArrayFunctions.DefaultPersistentFile);

                System.IO.File.WriteAllText(tmpFile, contents);
                PFW.CSIST203.Project1.Functions.ArrayFunctions obj = new PFW.CSIST203.Project1.Functions.ArrayFunctions();
                string[] data = null;
                AssertDelegateSuccess(() =>
                {
                    data = obj.Load(array.Length);
                }, "No failure reading the persistent file should have occurred");
                Assert.IsTrue(ArraysMatch(data, array), "The data read from the persistent file did not match the expected contents");
            }
Esempio n. 9
0
 private void FrmMain_Load(object sender, EventArgs e)
 {
     mathFunctions  = new PFW.CSIST203.Project1.Functions.MathFunctions();
     arrayFunctions = new PFW.CSIST203.Project1.Functions.ArrayFunctions();
     log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(System.AppDomain.CurrentDomain.SetupInformation.ConfigurationFile));
 }