コード例 #1
0
        public void Should_Be_Able_To_Store_Different_Values()
        {
            short expectedSize = 4;
            short expectedCount = 4;

            StoredColors colors = new StoredColors();
            colors.Add(100);
            colors.Add(200);
            colors.Add(300);
            colors.Add(400);

            Assert.AreEqual(expectedSize, colors.Count);
        }
コード例 #2
0
        public void Should_Be_Able_To_Store_Same_Value()
        {
            short expectedSize = 1;
            short expectedCount = 4;

            StoredColors colors = new StoredColors();
            colors.Add(100);
            colors.Add(100);
            colors.Add(100);
            colors.Add(100);

            Assert.AreEqual(expectedSize, colors.Count);
            Assert.AreEqual(expectedCount, colors[100]);
        }
コード例 #3
0
        public bool Traverse()
        {
            if (adjacencyList == null)
            {
                throw new ArgumentException("Missing initialization arguments");
            }

            markedVertices = new bool[adjacencyList.Count + 1];
            List<int> adjacentWithRootColor = new List<int>();
            StoredColors storedColors = new StoredColors();
            int head = 1;
            traversalQueue.Enqueue(head);
            markedVertices[head] = true;

            short headColor = verticesColoring[head];
            adjacentWithRootColor.Add(head);

            while (traversalQueue.Any())
            {
                int node = traversalQueue.Dequeue();
                Console.WriteLine(node);

                foreach (int tail in adjacencyList[node])
                {
                    if (markedVertices[tail])
                        continue;

                    // if tail has diff color add it to counter
                    if (verticesColoring[tail] != headColor)
                    {
                        storedColors.Add(verticesColoring[tail]);
                        markedVertices[tail] = true; // it's probably redundant, but in time pressure conditions I'd like to have it there. TODO check
                        continue;
                    }

                    // if tail has same color, then store it for recoloring and continue traversal
                    adjacentWithRootColor.Add(tail);
                    markedVertices[tail] = true;
                    traversalQueue.Enqueue(tail);
                }
            }

            // short winnerColor = storedColors.First(x => x.Value == storedColors.Values.Max()).Key;

            var winnerColor = storedColors.FirstOrDefault(x => x.Value == storedColors.Values.Max());
            if (winnerColor.Equals(default(KeyValuePair<short, int>)))
            {
                return true;
            }

            Console.WriteLine("And the winner color is: {0}", winnerColor.Key);

            // recolor vertices
            foreach (int vertice in adjacentWithRootColor)
            {
                verticesColoring[vertice] = winnerColor.Key;
            }

            return false;
        }
コード例 #4
0
        public void Should_Be_Able_To_Store_Value()
        {
            short expected = 1;

            StoredColors colors = new StoredColors();
            colors.Add(100);

            Assert.AreEqual(expected, colors.Count);
        }
コード例 #5
0
 public void Should_Not_Be_Able_To_Use_Add()
 {
     StoredColors colors = new StoredColors();
     colors.Add(100, 100);
 }