コード例 #1
0
        public async Task Oblique_WhenNxNMatrix_ShouldReturnOblique()
        {
            var dna = new List <string>
            {
                "ABCDEF",
                "GHIJKL",
                "MNOPQR",
                "STUVWX",
                "YZ1234",
                "567890"
            };
            var oblique = new List <string>
            {
                "AHOV30",
                "FKPUZ5",
                "GNU29",
                "LQV16",
                "BIPW4",
                "EJOTY",
                "MT18",
                "RW27",
                "CJQX",
                "DINS"
            };
            var result = await UtilsArray.GetObliques(dna);

            Assert.Equal(result, oblique);
        }
コード例 #2
0
        public void MatrixMultiplicationTest()
        {
            int[,] matrix1 = {{1, 3, 5}, {4, 5, 7}, {5, 3, 1}};
            int[,] matrix2 = {{1, 3, 4}, {2, 5, 6}, {3, 6, 7}};
            int[,] expectedMatrix1 = {{22, 48, 57}, {35, 79, 95}, {14, 36, 45}};
            int[,] actualMatrix1 = UtilsArray.MatrixMultiplication(matrix1, matrix2);

            for (var i = 0; i < actualMatrix1.GetLength(0); i++)
            {
                for (var j = 0; j < actualMatrix1.GetLength(1); j++)
                {
                    Assert.IsTrue(actualMatrix1[i, j] == expectedMatrix1[i, j]);
                }
            }

            int[,] matrix3 = {{1, 2, 3}};
            int[,] matrix4 = {{4}, {5}, {6}};
            int[,] expectedMatrix2 = {{32}};
            int[,] actualMatrix2 = UtilsArray.MatrixMultiplication(matrix3, matrix4);

            for (var i = 0; i < actualMatrix2.GetLength(0); i++)
            {
                for (var j = 0; j < actualMatrix2.GetLength(1); j++)
                {
                    Assert.IsTrue(actualMatrix2[i, j] == expectedMatrix2[i, j]);
                }
            }

            int[,] matrix5 = {{1, 2, 3, 4}};
            int[,] matrix6 = {{4}, {5}, {6}};

            Assert.Throws<Exception>(() => UtilsArray.MatrixMultiplication(matrix5, matrix6));
        }
コード例 #3
0
        public async Task GetVerticals_WhenNxNMatrix_ShouldReturnTranspose()
        {
            var dna = new List <string>
            {
                "ABCDEF",
                "GHIJKL",
                "MNOPQR",
                "STUVWX",
                "YZ1234",
                "567890"
            };
            var transpose = new List <string>
            {
                "AGMSY5",
                "BHNTZ6",
                "CIOU17",
                "DJPV28",
                "EKQW39",
                "FLRX40",
            };

            var result = await UtilsArray.GetVerticals(dna);

            Assert.Equal(transpose, result);
        }
コード例 #4
0
        public void MultiplyMatrixByNumberTest()
        {
            int[,] inputMatrix = new int[,] {{11, 11, 11}, {11, 11, 11}, {11, 11, 11}};
            int[,] expectedMatrix = new int[,] {{55, 55, 55}, {55, 55, 55}, {55, 55, 55}};
            int k = 5;

            int[,] actualMatrix = UtilsArray.MultiplyMatrixByNumber(inputMatrix, k);
            Assert.That(actualMatrix, Is.EqualTo(expectedMatrix));
        }
コード例 #5
0
 public void GetRandomIntMatrixTest()
 {
     int[,] actualMatrix = UtilsArray.GetRandomIntMatrix(3, 3, 3, 3);
     Assert.IsTrue(actualMatrix.GetLength(0) == 3);
     Assert.IsTrue(actualMatrix.GetLength(1) == 3);
     for (var i = 0; i < actualMatrix.GetLength(0); i++)
     {
         for (var j = 0; j < actualMatrix.GetLength(1); j++)
         {
             Assert.IsTrue(actualMatrix[i, j] == 3);
         }
     }
 }
コード例 #6
0
 public void OperateIntArrTest(
     int[] arr1,
     int[] arr2,
     UtilsArray.ArrayOperation operation,
     int[] expectedResult
     )
 {
     if (arr1.Length == arr2.Length)
     {
         var actualArray = UtilsArray.OperateIntArr(arr1, arr2, operation);
         Assert.That(actualArray, Is.EqualTo(expectedResult));
     }
     else
     {
         Assert.Throws<Exception>(() => UtilsArray.OperateIntArr(arr1, arr2, operation));
     }
 }
コード例 #7
0
        public async Task <bool> IsMutant(List <string> dna)
        {
            var total = dna.Count(item => _itemsToSearch.Where(item.Contains).Any());

            if (total > 1)
            {
                return(true);
            }
            var verticals = await UtilsArray.GetVerticals(dna);

            total += verticals.Count(item => _itemsToSearch.Where(item.Contains).Any());
            if (total > 1)
            {
                return(true);
            }
            var obliques = await UtilsArray.GetObliques(dna);

            total += obliques.Count(item => _itemsToSearch.Where(item.Contains).Any());
            return(total > 1);
        }
コード例 #8
0
        public void SummationMatrixTest()
        {
            int[,] matrix1 = {{1, 3, 5}, {4, 5, 7}, {5, 3, 1}};
            int[,] matrix2 = {{1, 3, 4}, {2, 5, 6}, {3, 6, 7}};
            int[,] expectedMatrix1 = {{2, 6, 9}, {6, 10, 13}, {8, 9, 8}};
            int[,] expectedMatrix2 = {{0, 0, 1}, {2, 0, 1}, {2, -3, -6}};
            int[,] actualMatrix1 = UtilsArray.SummationMatrix(matrix1, matrix2, UtilsArray.MatrixOperation.Plus);
            int[,] actualMatrix2 = UtilsArray.SummationMatrix(matrix1, matrix2, UtilsArray.MatrixOperation.Minus);

            for (var i = 0; i < actualMatrix1.GetLength(0); i++)
            {
                for (var j = 0; j < actualMatrix1.GetLength(1); j++)
                {
                    Assert.IsTrue(actualMatrix1[i, j] == expectedMatrix1[i, j]);
                }
            }
            for (var i = 0; i < actualMatrix2.GetLength(0); i++)
            {
                for (var j = 0; j < actualMatrix2.GetLength(1); j++)
                {
                    Assert.IsTrue(actualMatrix2[i, j] == expectedMatrix2[i, j]);
                }
            }

            int[,] matrix5 = {{1, 3}, {4, 5}};
            int[,] matrix6 = {{1, 3, 4}, {2, 5, 6}, {3, 6, 7}};
            Assert.Throws<Exception>(() => UtilsArray.SummationMatrix(
                matrix5,
                matrix6,
                UtilsArray.MatrixOperation.Plus)
            );
            Assert.Throws<Exception>(() => UtilsArray.SummationMatrix(
                matrix5,
                matrix6,
                UtilsArray.MatrixOperation.Minus)
            );
        }
コード例 #9
0
 public void GetRandomIntArrTest(int size, int min, int max, int[] expectedResult)
 {
     var array = UtilsArray.GetRandomIntArr(size, min, max);
     Assert.That(array, Is.EqualTo(expectedResult));
 }
コード例 #10
0
    // retrieve Value of key
    public static string Value(string key,
                               string[] variables = null,
                               bool giveWarning   = true)
    {
        //
        // check for compound key
        if (key.IndexOf(SEPERATOR) > -1)
        {
            return(CompoundKey(key, variables, giveWarning));
        }

        //
        // ensure key starts with a '.'
        if (!IsKey(key))
        {
            if (giveWarning)
            {
                Logger.Warning("Received invalid key \"" + key + "\"", LocalizerID.WARNING_INVALID_KEY_PASSED);
            }

            return((Testing) ? TEST_RETURN : key);
        }

        string[] strlist = ExpandKey(key);
        if (strlist.Length > 1)
        {
            // found embedded variables in key
            if (variables != null)
            {
                if (giveWarning)
                {
                    // but variables were passed into Value()
                    Logger.Warning("Key \"" + key + "\" has embedded variables: " + UtilsArray.Print(strlist) + ", but was passed in variable parameters: " + UtilsArray.Print(variables), LocalizerID.WARNING_HAS_EMBEDDED_AND_PASSED_VARIABLES);
                }
            }
            else
            {
                // transfer embedded vars to variables list
                variables = new string[strlist.Length - 1];
                for (int i = 0; i < variables.Length; i++)
                {
                    variables[i] = strlist[i + 1];
                }
            }
        }
        key = strlist[0];

        // if assigned, use VariablesTinkerer delegate to modify variables list
        if (VariablesTinkerer != null && UtilsArray.HasValue(variables))
        {
            variables = VariablesTinkerer(variables);
        }

        //
        // retrieve value
        LocalizerValue stringKeyValue = LocalizerValue(key);
        string         value;

        if (stringKeyValue != null)
        {
            value = stringKeyValue.value;

            //
            // replace variables
            if (variables != null)
            {
                // save variables last used with this key
                stringKeyValue.Variables = variables;

                // substitute variables
                int counter = 0;
                foreach (string variableKey in variables)
                {
                    string variableValue       = Value(variableKey, null, false);
                    string replaceWithVariable = "";
                    replaceWithVariable += BRACES[0];
                    replaceWithVariable += counter++;
                    replaceWithVariable += BRACES[1];
                    value = value.Replace(replaceWithVariable, variableValue);
                }
            }
        }
        else
        {
            // if failed to get value, then use the key
            value = key;
        }

        return((Testing) ? TEST_RETURN : value);
    }