private bool BuildAndValidateXml()
        {
            // Build the Xml from TreeView
            var     doc      = new XmlDocument();
            XmlNode rootNode = doc.CreateElement("root");

            doc.AppendChild(rootNode);

            AddXmlNode(tvDefinition.Nodes[0], rootNode);
            definitionDoc = new XmlDocument();
            definitionDoc.LoadXml(doc.SelectSingleNode("root/ShuffleDefinition").OuterXml);

            var result = false;

            try
            {
                ShuffleHelper.ValidateDefinitionXml(definitionDoc, null);
                result = true;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }

            return(result);
        }
        protected override void ProcessRecord()
        {
            var Data = DataXml;

            if (Data == null && DataCsv != null)
            {
                try
                {
                    WriteVerbose("Xmlifying CSV data");
                    Data = ShuffleHelper.StringToXmlSerialized(DataCsv);
                }
                catch (Exception ex)
                {
                    WriteError(new ErrorRecord(ex, "StringToXmlSerialized", ErrorCategory.ReadError, Definition));
                }
            }
            try
            {
                WriteDebug("Importing");
                var result = Shuffler.QuickImport(Definition, Data, ShuffleListener, Container, Folder, true);
                var output = new ShuffleImportResult
                {
                    Created = result.Item1,
                    Updated = result.Item2,
                    Skipped = result.Item3,
                    Deleted = result.Item4,
                    Failed  = result.Item5
                };
                WriteObject(output);
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "QuickImport", ErrorCategory.ReadError, Definition));
            }
        }
        public void WhenListToShuffleIsIntResponseShouldBeInDifferentOrderToInput(int[] data)
        {
            var list          = data.ToList();
            var shuffleHelper = new ShuffleHelper <int>();
            var shuffledList  = shuffleHelper.ShuffleList(list);

            shuffledList.Should().NotEqual(list);
        }
示例#4
0
        private void DeployShuffleDefinition(IExecutionContainer container, Module module, string packagefolder, ref int created, ref int updated, ref int skipped, ref int deleted, ref int failed)
        {
            AddLogText(container, "---");
            AddLogText(container, $"Deploying module: {module}", false);
            var definitionfile = packagefolder + "\\" + module.File;

            AddLogText(container, $"Loading definition: {Path.GetFileName(definitionfile)}", false);
            var definition = new XmlDocument();

            definition.Load(definitionfile);
            var datafile = Path.ChangeExtension(definitionfile, ".data.xml");

            if (!string.IsNullOrWhiteSpace(module.DataFile))
            {
                datafile = GetDefinitionFilePath(module.DataFile);
            }
            container.Logger.Log($"Data File: {datafile}");
            XmlDocument data = null;

            if (File.Exists(datafile))
            {
                AddLogText(container, $"Loading data file: {Path.GetFileName(datafile)}", false);
                data = ShuffleHelper.LoadDataFile(datafile);
            }
            var definitionfolder = Path.GetDirectoryName(definitionfile);

            var result = Shuffler.QuickImport(container, definition, data, (object sender, ShuffleEventArgs e) => { ShuffleHandler(container, sender, e); }, definitionfolder, true);

            AddLogText(container, $"Module {module} totals:");
            AddLogText(container, $"  Created: {result.Item1}");
            AddLogText(container, $"  Updated: {result.Item2}");
            AddLogText(container, $"  Skipped: {result.Item3}");
            AddLogText(container, $"  Deleted: {result.Item4}");
            AddLogText(container, $"  Failed:  {result.Item5}");
            created += result.Item1;
            updated += result.Item2;
            skipped += result.Item3;
            deleted += result.Item4;
            failed  += result.Item5;
            if (result.Item5 > 0)
            {   // Fail count > 0
                var shufdef = definition.SelectSingleNode("ShuffleDefinition");
                if (shufdef != null)
                {
                    var stop = XML.GetBoolAttribute(shufdef, "StopOnError", false);
                    if (stop)
                    {
                        throw new Exception("Import failed. See log file for details.");
                    }
                }
            }
        }
示例#5
0
        public void DealIntoNewStackTest()
        {
            // Item 1: Deck size
            // Item 2: Start card index
            // Item 3: Expected end card index
            // Test examples taken from here:
            // https://adventofcode.com/2019/day/22
            var testData = new List <Tuple <int, int, int> >()
            {
                // To deal into new stack, create a new stack of cards by
                // dealing the top card of the deck onto the top of the new
                // stack repeatedly until you run out of cards:
                //Top Bottom
                //0 1 2 3 4 5 6 7 8 9   Your deck
                //                      New stack
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //                  0   New stack
                //
                //    2 3 4 5 6 7 8 9   Your deck
                //                1 0   New stack
                //
                //      3 4 5 6 7 8 9   Your deck
                //              2 1 0   New stack
                //
                //Several steps later...
                //
                //                  9   Your deck
                //  8 7 6 5 4 3 2 1 0   New stack
                //
                //                      Your deck
                //9 8 7 6 5 4 3 2 1 0   New stack
                Tuple.Create(10, 0, 9),
                Tuple.Create(10, 1, 8),
                Tuple.Create(10, 2, 7),
                Tuple.Create(10, 3, 6),
                Tuple.Create(10, 4, 5),
                Tuple.Create(10, 5, 4),
                Tuple.Create(10, 6, 3),
                Tuple.Create(10, 7, 2),
                Tuple.Create(10, 8, 1),
                Tuple.Create(10, 9, 0),
            };

            foreach (var testExample in testData)
            {
                var result = ShuffleHelper
                             .GetShuffleFunctionDealIntoNewStack(deckSize: testExample.Item1)
                             .Evaluate(testExample.Item2);
                Assert.Equal(testExample.Item3, result);
            }
        }
示例#6
0
 private void txtFile_TextChanged(object sender, EventArgs e)
 {
     ExtractShufflePlaceholders();
     datafilerequired = ShuffleHelper.DataFileRequired(txtFile.Text);
     if (datafilerequired)
     {
         txtData.Text = Path.ChangeExtension(txtFile.Text, ".data.xml");
     }
     else
     {
         txtData.Text = "";
     }
     EnableShuffle();
 }
示例#7
0
        private bool BuildAndValidateXml(bool validate = true)
        {
            var result = true;

            if (tvDefinition.Nodes.Count > 0 && validate)
            {
                // Build the Xml from TreeView
                var def = GetDefinitionDocument();
                try
                {
                    ShuffleHelper.ValidateDefinitionXml(def, null);
                }
                catch (Exception ex)
                {
                    result = false;
                    MessageBox.Show(ex.Message);
                }
            }
            return(result);
        }
示例#8
0
 public ControlBase(string nodename, Dictionary <string, string> collection, ShuffleBuilder shuffleBuilder)
     : this()
 {
     this.shuffleBuilder = shuffleBuilder;
     if (collection != null)
     {
         attributeCollection = collection;
     }
     else
     {
         attributeCollection = new Dictionary <string, string>();
     }
     Saved += shuffleBuilder.CtrlSaved;
     if (string.IsNullOrEmpty(nodename))
     {
         nodename = GetCallingNodeName();
     }
     txtInfo.Text   = ShuffleHelper.GetNodeDocumentation(nodename);
     gbInfo.Visible = !string.IsNullOrEmpty(txtInfo.Text);
     LayoutControls();
 }
示例#9
0
        protected override void ProcessRecord()
        {
            var Data = DataXml;

            if (Data == null && DataCsv != null)
            {
                try
                {
                    WriteVerbose("Xmlifying CSV data");
                    Data = ShuffleHelper.StringToXmlSerialized(DataCsv);
                }
                catch (Exception ex)
                {
                    WriteError(new ErrorRecord(ex, "StringToXmlSerialized", ErrorCategory.ReadError, Definition));
                }
            }
            try
            {
                WriteDebug("Importing");
                var dataList = new Dictionary <string, XmlDocument>
                {
                    { string.Empty, Data }
                };

                var result = Shuffler.QuickImport(new ShuffleContainer(this), Definition, dataList, ShuffleListener, Folder, true);
                var output = new ShuffleImportResult
                {
                    Created = result.created,
                    Updated = result.updated,
                    Skipped = result.skipped,
                    Deleted = result.deleted,
                    Failed  = result.failed
                };
                WriteObject(output);
            }
            catch (Exception ex)
            {
                WriteError(new ErrorRecord(ex, "QuickImport", ErrorCategory.ReadError, Definition));
            }
        }
示例#10
0
        /// <summary>
        /// Read all directory as Entity Name and then all files as records
        /// </summary>
        /// <param name="fileWithPath"></param>
        /// <returns></returns>
        private static Dictionary <string, XmlDocument> ReadFilesFromDisk(string fileWithPath)
        {
            var pathToBaseFilder = Path.GetDirectoryName(fileWithPath);
            var directories      = Directory.GetDirectories(pathToBaseFilder);

            var deserializedData = new Dictionary <string, XmlDocument>();

            foreach (var directory in directories)
            {
                var directoryName = Path.GetFileName(directory);
                var files         = Directory.GetFiles(directory, "*.xml");
                foreach (var file in files)
                {
                    var fileName       = Path.GetFileName(file);
                    var fullPathToFile = file;

                    deserializedData.Add(Path.Combine(directoryName, fileName), ShuffleHelper.LoadDataFile(fullPathToFile));
                }
            }

            return(deserializedData);
        }
示例#11
0
        private void SetDataFile()
        {
            var def = GetDefinitionFilePath(txtModuleFile.Text);

            if (File.Exists(def))
            {
                if (ShuffleHelper.DataFileRequired(def))
                {
                    var data = GetDefinitionFilePath(txtModuleDataFile.Text);
                    if (!File.Exists(data))
                    {
                        txtModuleDataFile.Text = Path.ChangeExtension(txtModuleFile.Text, ".data.xml");
                    }
                    txtModuleDataFile.Enabled = true;
                }
                else
                {
                    txtModuleDataFile.Text    = "";
                    txtModuleDataFile.Enabled = false;
                }
            }
            btnOpenDataFile.Enabled = txtModuleDataFile.Enabled;
            btnShowDataFile.Enabled = txtModuleDataFile.Enabled;
        }
示例#12
0
        private void BuildTest()
        {
            if (NumOfQ != TestsRegister.GetNumQ(TestID))
            {
                Ring.IsActive = false;

                int listLength = Questions.Count;
                randomInt = UpdateRandom(listLength);

                Debug.WriteLine("Random " + randomInt);

                Question.Text = Questions[randomInt];

                selectedQuestionList.Add(Ans1[randomInt]); // 0
                selectedQuestionList.Add(Ans2[randomInt]); // 1
                selectedQuestionList.Add(Ans3[randomInt]); // 2
                selectedQuestionList.Add(Ans4[randomInt]); // 3
                selectedQuestionList.Add(Ans5[randomInt]); // 4

                ShuffleHelper.Shuffle <string>(selectedQuestionList);

                Answer1.Content = selectedQuestionList[0];
                Answer2.Content = selectedQuestionList[1];
                Answer3.Content = selectedQuestionList[2];
                Answer4.Content = selectedQuestionList[3];
                Answer5.Content = selectedQuestionList[4];

                basetime = time;
                ProgressBarTime.Value = time;
                TimerEngine();
                timer.Start();

                NumOfQ++;
            }
            else
            {
                List <int> finalTime = new List <int>();
                Debug.WriteLine("Proces bol ukončený!");

                foreach (var time_ in AnsTime)
                {
                    finalTime.Add(time - time_);
                }

                foreach (var nullcount in IncorrectAns)
                {
                    if (nullcount == null)
                    {
                        NoAnsCount++;
                    }
                }

                double AvgTime = finalTime.Average();


                var pnts = (CorrectAnsCount / 0.50) / AvgTime;
                Points = (int)pnts;

                var totalAns = CorrectAnsCount + IncorrectAnsCount;
                Percentage = (100 * CorrectAnsCount) / totalAns;

                if (Percentage >= 90)
                {
                    Mark = 1;
                }
                if (Percentage >= 75 && Percentage < 90)
                {
                    Mark = 2;
                }
                if (Percentage >= 65 && Percentage < 75)
                {
                    Mark = 3;
                }
                if (Percentage >= 40 && Percentage < 65)
                {
                    Mark = 4;
                }
                if (Percentage < 40)
                {
                    Mark = 5;
                }

                SaveDataService sdc = new SaveDataService(CorrectAnsCount, IncorrectAnsCount, IncorrectAns, AvgTime, TestID, Mark, Percentage);

                var parameters = new PassDataModel();
                parameters.CorrectAnsCount   = this.CorrectAnsCount;
                parameters.IncorrectAnsCount = this.IncorrectAnsCount;
                parameters.IncorrectAns      = this.IncorrectAns;
                parameters.AvgTime           = AvgTime;
                parameters.Date         = DateTime.Now;
                parameters.NoAnsCount   = NoAnsCount;
                parameters.Points       = Points;
                parameters.Mark         = Mark;
                parameters.Announcement = Annouc();
                parameters.Percentage   = Percentage;
                parameters.IncQuestions = IncQuestions;
                parameters.ID           = TestID;

                this.Frame.Navigate(typeof(SummaryPage), parameters);
            }
        }
示例#13
0
        public void DealWithIncrementNTest()
        {
            // Item 1: Deck size
            // Item 2: N
            // Item 3: Start card index
            // Item 4: Expected end card index
            // Test examples taken from here:
            // https://adventofcode.com/2019/day/22
            var testData = new List <Tuple <int, int, int, int> >()
            {
                // To deal with increment N, start by clearing enough space on
                // your table to lay out all of the cards individually in a long
                // line. Deal the top card into the leftmost position. Then, move
                // N positions to the right and deal the next card there. If you
                // would move into a position past the end of the space on your
                // table, wrap around and keep counting from the leftmost card
                // again.
                // Continue this process until you run out of cards.
                // For example, to deal with increment 3:
                //0 1 2 3 4 5 6 7 8 9   Your deck
                //. . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Deal the top card to the current position:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Move the current position right 3:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //      ^               Current position
                //
                //Deal the top card:
                //
                //    2 3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . . . . .   Space on table
                //      ^               Current position
                //
                //Move right 3 and deal:
                //
                //      3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . .   Space on table
                //            ^         Current position
                //
                //Move right 3 and deal:

                //        4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . 3   Space on table
                //                  ^   Current position
                //
                //Move right 3, wrapping around, and deal:
                //
                //          5 6 7 8 9   Your deck
                //0 . 4 1 . . 2 . . 3   Space on table
                //    ^                 Current position
                //
                //And so on:
                //
                //0 7 4 1 8 5 2 9 6 3   Space on table

                Tuple.Create(10, 3, 0, 0),
                Tuple.Create(10, 3, 1, 3),
                Tuple.Create(10, 3, 2, 6),
                Tuple.Create(10, 3, 3, 9),
                Tuple.Create(10, 3, 4, 2),
                Tuple.Create(10, 3, 5, 5),
                Tuple.Create(10, 3, 6, 8),
                Tuple.Create(10, 3, 7, 1),
                Tuple.Create(10, 3, 8, 4),
                Tuple.Create(10, 3, 9, 7),
            };

            foreach (var testExample in testData)
            {
                var result = ShuffleHelper.GetShuffleFunctionDealWithIncrementN(
                    n: testExample.Item2,
                    deckSize: testExample.Item1)
                             .Evaluate(testExample.Item3);
                Assert.Equal(testExample.Item4, result);
            }
        }
示例#14
0
        public TopicManagerTests()
        {
            var shuffleHelper = new ShuffleHelper <string>();

            _topicManager = new TopicManager(shuffleHelper);
        }
示例#15
0
        private void btnShuffle_Click(object sender, EventArgs e)
        {
            lbLog.Items.Clear();
            var type = cmbType.SelectedItem != null ? (SerializationType)cmbType.SelectedItem : SerializationType.Simple;

            WorkAsync(new WorkAsyncInfo("Doing the Shuffle...",
                                        (eventargs) =>
            {
                shuffeling = true;
                EnableShuffle();
                var logpath   = Path.Combine(Paths.LogsPath, "ShuffleRunner");
                var container = new CintContainer(new CrmServiceProxy(Service), logpath, true);
                var log       = container.Logger;
                var location  = System.Reflection.Assembly.GetExecutingAssembly().Location;
                var verinfo   = FileVersionInfo.GetVersionInfo(location);
                log.Log("  ***  {0} ***", verinfo.Comments.PadRight(50));
                log.Log("  ***  {0} ***", verinfo.LegalCopyright.PadRight(50));
                log.Log("  ***  {0} ***", (verinfo.InternalName + ", " + verinfo.FileVersion).PadRight(50));
                var definition = new XmlDocument();
                definition.Load(txtFile.Text);
                ReplaceShufflePlaceholders(definition);
                var definitionpath = Path.GetDirectoryName(txtFile.Text);
                try
                {
                    if (rbExport.Checked)
                    {
                        var export = Shuffler.QuickExport(definition, type, ';', ShuffleEventHandler, container, definitionpath);
                        if (export != null)
                        {
                            export.Save(txtData.Text);
                            AddLogText("Export saved to: " + txtData.Text);
                        }
                    }
                    else if (rbImport.Checked)
                    {
                        XmlDocument data = null;
                        if (datafilerequired)
                        {
                            AddLogText("Loading data from: " + txtData.Text);
                            data = ShuffleHelper.LoadDataFile(txtData.Text);
                        }
                        var importresult = Shuffler.QuickImport(definition, data, ShuffleEventHandler, container, definitionpath);
                        AddLogText("---");
                        AddLogText(string.Format("Created: {0}", importresult.Item1));
                        AddLogText(string.Format("Updated: {0}", importresult.Item2));
                        AddLogText(string.Format("Skipped: {0}", importresult.Item3));
                        AddLogText(string.Format("Deleted: {0}", importresult.Item4));
                        AddLogText(string.Format("Failed : {0}", importresult.Item5));
                        AddLogText("---");
                    }
                }
                catch (Exception ex)
                {
                    log.Log(ex);
                    throw;
                }
                finally
                {
                    log.CloseLog();
                    shuffeling = false;
                    EnableShuffle();
                }
            })
            {
                PostWorkCallBack =
                    (completedeventargs) =>
                {
                    if (completedeventargs.Error != null)
                    {
                        AddLogText(completedeventargs.Error.Message);
                    }
                }
            });
        }
示例#16
0
        public void DealWithIncrementNBackwardsTest()
        {
            // Item 1: Deck size
            // Item 2: N
            // Item 3: Start card index
            // Item 4: Expected end card index
            // Test examples taken from here:
            // https://adventofcode.com/2019/day/22
            var testData = new List <Tuple <int, int, int, int> >()
            {
                // To deal with increment N, start by clearing enough space on
                // your table to lay out all of the cards individually in a long
                // line. Deal the top card into the leftmost position. Then, move
                // N positions to the right and deal the next card there. If you
                // would move into a position past the end of the space on your
                // table, wrap around and keep counting from the leftmost card
                // again.
                // Continue this process until you run out of cards.
                // For example, to deal with increment 3:
                //0 1 2 3 4 5 6 7 8 9   Your deck
                //. . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Deal the top card to the current position:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //^                     Current position
                //
                //Move the current position right 3:
                //
                //  1 2 3 4 5 6 7 8 9   Your deck
                //0 . . . . . . . . .   Space on table
                //      ^               Current position
                //
                //Deal the top card:
                //
                //    2 3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . . . . .   Space on table
                //      ^               Current position
                //
                //Move right 3 and deal:
                //
                //      3 4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . .   Space on table
                //            ^         Current position
                //
                //Move right 3 and deal:

                //        4 5 6 7 8 9   Your deck
                //0 . . 1 . . 2 . . 3   Space on table
                //                  ^   Current position
                //
                //Move right 3, wrapping around, and deal:
                //
                //          5 6 7 8 9   Your deck
                //0 . 4 1 . . 2 . . 3   Space on table
                //    ^                 Current position
                //
                //And so on:
                //
                //0 7 4 1 8 5 2 9 6 3   Space on table
                Tuple.Create(10, 3, 0, 0),
                Tuple.Create(10, 3, 1, 7),
                Tuple.Create(10, 3, 2, 4),
                Tuple.Create(10, 3, 3, 1),
                Tuple.Create(10, 3, 4, 8),
                Tuple.Create(10, 3, 5, 5),
                Tuple.Create(10, 3, 6, 2),
                Tuple.Create(10, 3, 7, 9),
                Tuple.Create(10, 3, 8, 6),
                Tuple.Create(10, 3, 9, 3),

                // Deck size 10, deal with increment 7:
                // 00 01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69
                // 0                    1                    2                    3                    4                    5                    6                    7                    8                    9
                // =>
                // 00 01 02 03 04 05 06 07 08 09
                // 0                    1
                // 10 11 12 13 14 15 16 17 18 19
                //             2
                // 20 21 22 23 24 25 26 27 28 29
                //    3                    4
                // 30 31 32 33 34 35 36 37 38 39
                //                5
                // 40 41 42 43 44 45 46 47 48 49
                //       6                    7
                // 50 51 52 53 54 55 56 57 58 59
                //                   8
                // 60 61 62 63 64 65 66 67 68 69
                //          9
                // ->
                // 0  3  6  9  2  5  8  1  4  7
                Tuple.Create(10, 7, 0, 0),
                Tuple.Create(10, 7, 1, 3),
                Tuple.Create(10, 7, 2, 6),
                Tuple.Create(10, 7, 3, 9),
                Tuple.Create(10, 7, 4, 2),
                Tuple.Create(10, 7, 5, 5),
                Tuple.Create(10, 7, 6, 8),
                Tuple.Create(10, 7, 7, 1),
                Tuple.Create(10, 7, 8, 4),
                Tuple.Create(10, 7, 9, 7),
            };

            foreach (var testExample in testData)
            {
                var result = ShuffleHelper.GetShuffleFunctionDealWithIncrementN(
                    n: testExample.Item2,
                    deckSize: testExample.Item1)
                             .GetInverse()
                             .Evaluate(testExample.Item3);
                Assert.Equal(testExample.Item4, result);
            }
        }
示例#17
0
        public void ShuffleTest()
        {
            // Item 1: Shuffle instructions
            // Item 2: Deck size
            // Item 3: Final cards order
            // Test examples taken from here:
            // https://adventofcode.com/2019/day/22
            var testData = new List <Tuple <string[], int, int[]> >()
            {
                //  Here are some examples that combine techniques; they all start with a factory order deck of 10 cards:

                //deal with increment 7
                //deal into new stack
                //deal into new stack
                //Result: 0 3 6 9 2 5 8 1 4 7
                Tuple.Create(new string[]
                {
                    "deal with increment 7",
                    "deal into new stack",
                    "deal into new stack",
                }, 10, new int[] { 0, 3, 6, 9, 2, 5, 8, 1, 4, 7, }),

                //cut 6
                //deal with increment 7
                //deal into new stack
                //Result: 3 0 7 4 1 8 5 2 9 6
                Tuple.Create(new string[]
                {
                    "cut 6",
                    "deal with increment 7",
                    "deal into new stack",
                }, 10, new int[] { 3, 0, 7, 4, 1, 8, 5, 2, 9, 6, }),

                //deal with increment 7
                //deal with increment 9
                //cut -2
                //Result: 6 3 0 7 4 1 8 5 2 9
                Tuple.Create(new string[]
                {
                    "deal with increment 7",
                    "deal with increment 9",
                    "cut -2",
                }, 10, new int[] { 6, 3, 0, 7, 4, 1, 8, 5, 2, 9, }),

                //deal into new stack
                //cut -2
                //deal with increment 7
                //cut 8
                //cut -4
                //deal with increment 7
                //cut 3
                //deal with increment 9
                //deal with increment 3
                //cut -1
                //Result: 9 2 5 8 1 4 7 0 3 6
                Tuple.Create(new string[]
                {
                    "deal into new stack",
                    "cut -2",
                    "deal with increment 7",
                    "cut 8",
                    "cut -4",
                    "deal with increment 7",
                    "cut 3",
                    "deal with increment 9",
                    "deal with increment 3",
                    "cut -1",
                }, 10, new int[] { 9, 2, 5, 8, 1, 4, 7, 0, 3, 6, }),
            };

            foreach (var testExample in testData)
            {
                var shuffleInstructions = ShuffleHelper.GetShuffleInstructions(testExample.Item1);
                var result = ShuffleHelper.ShuffleDeck(
                    deckSize: testExample.Item2,
                    shuffleInstructions: shuffleInstructions);
                Assert.Equal(testExample.Item3, result);
            }
        }
        public LetterManagerTests()
        {
            var shuffleHelper = new ShuffleHelper <string>();

            _letterManager = new LetterManager(shuffleHelper);
        }
示例#19
0
        public void CutNCardsTest()
        {
            // Item 1: Deck size
            // Item 2: Cut size
            // Item 3: Start card index
            // Item 4: Expected end card index
            // Test examples taken from here:
            // https://adventofcode.com/2019/day/22
            var testData = new List <Tuple <int, int, int, int> >()
            {
                // To cut N cards, take the top N cards off the top of the
                // deck and move them as a single unit to the bottom of the
                // deck, retaining their order. For example, to cut 3:
                //Top          Bottom
                //0 1 2 3 4 5 6 7 8 9   Your deck
                //
                //      3 4 5 6 7 8 9   Your deck
                //0 1 2                 Cut cards
                //
                //3 4 5 6 7 8 9         Your deck
                //              0 1 2   Cut cards
                //
                //3 4 5 6 7 8 9 0 1 2   Your deck
                Tuple.Create(10, 3, 0, 7),
                Tuple.Create(10, 3, 1, 8),
                Tuple.Create(10, 3, 2, 9),
                Tuple.Create(10, 3, 3, 0),
                Tuple.Create(10, 3, 4, 1),
                Tuple.Create(10, 3, 5, 2),
                Tuple.Create(10, 3, 6, 3),
                Tuple.Create(10, 3, 7, 4),
                Tuple.Create(10, 3, 8, 5),
                Tuple.Create(10, 3, 9, 6),
                // You've also been getting pretty good at a version of this
                // technique where N is negative! In that case, cut (the
                // absolute value of) N cards from the bottom of the deck onto
                // the top. For example, to cut -4:
                //Top          Bottom
                //0 1 2 3 4 5 6 7 8 9   Your deck
                //
                //0 1 2 3 4 5           Your deck
                //            6 7 8 9   Cut cards
                //
                //        0 1 2 3 4 5   Your deck
                //6 7 8 9               Cut cards
                //
                //6 7 8 9 0 1 2 3 4 5   Your deck
                Tuple.Create(10, -4, 0, 4),
                Tuple.Create(10, -4, 1, 5),
                Tuple.Create(10, -4, 2, 6),
                Tuple.Create(10, -4, 3, 7),
                Tuple.Create(10, -4, 4, 8),
                Tuple.Create(10, -4, 5, 9),
                Tuple.Create(10, -4, 6, 0),
                Tuple.Create(10, -4, 7, 1),
                Tuple.Create(10, -4, 8, 2),
                Tuple.Create(10, -4, 9, 3),
            };

            foreach (var testExample in testData)
            {
                var result = ShuffleHelper.GetShuffleFunctionCutNCards(
                    n: testExample.Item2,
                    deckSize: testExample.Item1)
                             .Evaluate(testExample.Item3);
                Assert.Equal(testExample.Item4, result);
            }
        }