Пример #1
0
        public void When_BitStringToBool()
        {
            string source   = "1";
            bool   expected = true;
            bool   actual;

            actual = BoolExtensions.BitStringToBool(source);
            Assert.AreEqual(expected, actual);
        }
Пример #2
0
        public void When_IfFalse()
        {
            bool source   = false;
            bool expected = false;
            bool actual;

            actual = BoolExtensions.IfFalse(source, () => Assert.AreEqual(expected, source));
            Assert.AreEqual(expected, actual);
        }
Пример #3
0
        public void When_ToYesNoString()
        {
            bool   source   = false;
            string expected = "No";
            string actual;

            actual = BoolExtensions.ToYesNoString(source);
            Assert.AreEqual(expected, actual);
        }
Пример #4
0
        public void When_BitIntToBool()
        {
            int  source   = 0;     // TODO: Initialize to an appropriate value
            bool expected = false; // TODO: Initialize to an appropriate value
            bool actual;

            actual = BoolExtensions.BitIntToBool(source);
            Assert.AreEqual(expected, actual);
        }
Пример #5
0
        public void When_ToBitString()
        {
            bool   source   = true;
            string expected = "1";
            string actual;

            actual = BoolExtensions.ToBitString(source);
            Assert.AreEqual(expected, actual);
        }
Пример #6
0
        public void When_ToBitInt()
        {
            bool source   = false;
            int  expected = 0;
            int  actual;

            actual = BoolExtensions.ToBitInt(source);
            Assert.AreEqual(expected, actual);
        }
Пример #7
0
 protected static bool IncludeAssemblyWhenCopyingDeps(AssemblyReference assemblyReference, Regex[] assemblyNamePatterns, bool ignoreOnlyMatching)
 {
     if (assemblyNamePatterns.Any())
     {
         return(BoolExtensions.Flip(assemblyNamePatterns.Any(r => r.IsMatch(assemblyReference.Name)), ignoreOnlyMatching));
     }
     // when no patterns are given, include all assemblies (don't filter)
     return(true);
 }
Пример #8
0
        public void When_YesNoToBool()
        {
            string source     = "Yes";
            bool   ignoreCase = false;
            bool   expected   = true;
            bool   actual;

            actual = BoolExtensions.YesNoToBool(source, ignoreCase);
            Assert.AreEqual(expected, actual);
        }
Пример #9
0
        /// <summary>
        /// Validates that the assembly references have valid hint paths.
        /// <para>(Not validated automatically, you must call this if you want to validate)</para>
        /// </summary>
        public void ValidateHintPaths(Regex[] assemblyNamePatterns, bool ignoreOnlyMatching)
        {
            var invalidHintPathAssemblies = this.AssemblyReferences
                                            .Where(x => String.IsNullOrWhiteSpace(x.HintPath));

            if (assemblyNamePatterns.Any())
            {
                // Filter assemblies only if some patterns were given.
                invalidHintPathAssemblies = invalidHintPathAssemblies
                                            .Where(x => BoolExtensions.Flip(assemblyNamePatterns.Any(r => r.IsMatch(x.Name)), ignoreOnlyMatching));
            }

            if (invalidHintPathAssemblies.Any())
            {
                var errorMessage = String.Format("Found assembly references with empty HintPaths in project '{0}'. Assembly references:\n{1}",
                                                 this.ToString(),
                                                 StringExtensions.Tabify(invalidHintPathAssemblies.Select(x => x.ToString())));
                _logger.Debug(errorMessage);
            }
        }
Пример #10
0
        public static NpmVersionComparison GetComparison(NpmVersion version1, NpmVersion version2)
        {
            bool?majorMatch           = null;
            bool?minorMatch           = null;
            bool?patchMatch           = null;
            bool?major1Greater        = null;
            bool?minor1Greater        = null;
            bool?patch1Greater        = null;
            var  comparison           = NpmVersionComparison.NoComparison;
            var  skipDeeperComparison = false;

            if (version1.MatchesAll || version2.MatchesAll)
            {
                comparison           = NpmVersionComparison.Matches;
                skipDeeperComparison = true;
            }
            else if (version1.HasWildcard || version2.HasWildcard)
            {
                NpmVersion npmWildcard = null;
                NpmVersion npmMatch    = null;
                Regex      regex       = null;

                if (version1.HasWildcard)
                {
                    npmWildcard = version1;
                    npmMatch    = version2.ToPaddedVersion();
                }
                else if (version2.HasWildcard)
                {
                    npmWildcard = version2;
                    npmMatch    = version1.ToPaddedVersion();
                }
                else
                {
                    DebugUtils.Break();
                }

                regex = npmWildcard.GetRegexFromWildchard();

                if (regex.IsMatch(npmMatch.VersionTuple))
                {
                    comparison = NpmVersionComparison.Matches;
                }
                else
                {
                    comparison = NpmVersionComparison.NotEquals;
                }

                skipDeeperComparison = true;
            }
            else if (version1.VersionRangeLower != null && version1.VersionRangeHigher != null)
            {
                if (version2 >= version1.VersionRangeLower && version2 <= version1.VersionRangeHigher)
                {
                    comparison = NpmVersionComparison.Matches;
                }
                else
                {
                    comparison = NpmVersionComparison.NotEquals;
                }

                skipDeeperComparison = true;
            }
            else if (version2.VersionRangeLower != null && version2.VersionRangeHigher != null)
            {
                if (version1 >= version2.VersionRangeLower && version1 <= version2.VersionRangeHigher)
                {
                    comparison = NpmVersionComparison.Matches;
                }
                else
                {
                    comparison = NpmVersionComparison.NotEquals;
                }

                skipDeeperComparison = true;
            }

            if (!skipDeeperComparison)
            {
                if (version1.Version == null)
                {
                    if (version2.Version == null)
                    {
                        comparison           = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        skipDeeperComparison = true;
                    }
                    else
                    {
                        comparison           = NpmVersionComparison.GreaterThan | NpmVersionComparison.Matches;
                        skipDeeperComparison = true;
                    }
                }
                else if (version2.Version != null)
                {
                    if (version1.Version == version2.Version)
                    {
                        comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;

                        if (!version1.HasRangeComparison && !version2.HasRangeComparison)
                        {
                            skipDeeperComparison = true;
                        }
                    }
                }

                if (version1.Major == null)
                {
                    if (version2.Major == null)
                    {
                        comparison           = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        skipDeeperComparison = true;
                    }
                    else
                    {
                        comparison           = NpmVersionComparison.LessThan;
                        skipDeeperComparison = true;
                    }
                }
            }

            if (!skipDeeperComparison)
            {
                if (version1.Major == null && version2.Major != null)
                {
                    major1Greater = false;
                }
                else if (version1.Major != null && version2.Major == null)
                {
                    major1Greater = true;
                }
                else if (version1.Major == version2.Major)
                {
                    majorMatch = true;

                    if (version1.Minor != null)
                    {
                        if (version2.Minor != null)
                        {
                            if (version1.Minor == version2.Minor)
                            {
                                minorMatch = true;  // majors and minors match

                                if (version1.Patch != null)
                                {
                                    if (version2.Patch != null)
                                    {
                                        if (version1.Patch == version2.Patch)
                                        {
                                            patchMatch = true;  // majors, minors, and patches match
                                        }
                                        else
                                        {
                                            patch1Greater = version1.Patch > version2.Patch;
                                        }
                                    }
                                    else
                                    {
                                        patch1Greater = true;
                                    }
                                }
                                else if (version2.Patch != null)
                                {
                                    patch1Greater = false;  // v1 has no patch, v2 does
                                }
                                else
                                {
                                    // both have no patch
                                    patch1Greater = false;
                                }
                            }
                            else
                            {
                                minor1Greater = version1.Minor > version2.Minor;
                            }
                        }
                        else
                        {
                            minor1Greater = true;
                        }
                    }
                    else if (version2.Minor != null)
                    {
                        minor1Greater = false;  // v1 has no minor, v2 does
                    }
                    else
                    {
                        // both have no minor
                        minor1Greater = false;
                    }
                }
                else
                {
                    major1Greater = version1.Major > version2.Major;
                    majorMatch    = false;
                }

                if (version1.Prefix != string.Empty && version2.Prefix != string.Empty)
                {
                    comparison = NpmVersionComparison.NotEquals; // versions did not equal above
                }
                else if (version1.Prefix == string.Empty && version2.Prefix == string.Empty)
                {
                    if (patch1Greater.IsValueTrue())
                    {
                        comparison = NpmVersionComparison.GreaterThan;
                    }
                    else if (minor1Greater.IsValueTrue())
                    {
                        comparison = NpmVersionComparison.GreaterThan;
                    }
                    else if (major1Greater.IsValueTrue())
                    {
                        comparison = NpmVersionComparison.GreaterThan;
                    }
                    else if (patch1Greater.IsValueFalse())
                    {
                        comparison = NpmVersionComparison.LessThan;
                    }
                    else if (minor1Greater.IsValueFalse())
                    {
                        comparison = NpmVersionComparison.LessThan;
                    }
                    else if (major1Greater.IsValueFalse())
                    {
                        comparison = NpmVersionComparison.LessThan;
                    }
                    else
                    {
                        DebugUtils.Break();
                        comparison = NpmVersionComparison.LessThan;
                    }
                }
                else
                {
                    // left has the prefix, matching to right.  Left in general must be less than or equal to right

                    switch (version1.Prefix)
                    {
                    case "^":

                        if (version2.VersionTuple == version1.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (major1Greater.IsValueTrue())
                        {
                            comparison = NpmVersionComparison.GreaterThan;
                        }
                        else if (major1Greater.IsValueFalse())
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }
                        else if (majorMatch.IsValueTrue())
                        {
                            if (BoolExtensions.AnyAreValueTrue(patch1Greater, minor1Greater))
                            {
                                comparison = NpmVersionComparison.GreaterThan;
                            }
                            else if (BoolExtensions.AnyAreValueFalse(patch1Greater, minor1Greater))
                            {
                                comparison = NpmVersionComparison.LessThan | NpmVersionComparison.Matches;
                            }
                            else if (minorMatch.IsValueTrue())
                            {
                                comparison = NpmVersionComparison.Matches;
                            }
                            else
                            {
                                DebugUtils.Break();
                            }
                        }

                        break;

                    case "~":

                        if (version2.VersionTuple == version1.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (BoolExtensions.AnyAreValueTrue(major1Greater, minor1Greater))
                        {
                            comparison = NpmVersionComparison.GreaterThan;
                        }
                        else if (BoolExtensions.AnyAreValueFalse(major1Greater, minor1Greater))
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }
                        else if (minorMatch.IsValueTrue())
                        {
                            if (patch1Greater.IsValueTrue())
                            {
                                comparison = NpmVersionComparison.GreaterThan;
                            }
                            else if (patch1Greater.IsValueFalse())
                            {
                                comparison = NpmVersionComparison.LessThan | NpmVersionComparison.Matches;
                            }
                            else if (patchMatch.IsValueTrue())
                            {
                                comparison = NpmVersionComparison.Matches;
                            }
                            else
                            {
                                DebugUtils.Break();
                            }
                        }

                        break;

                    case ">":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals;
                        }
                        else if (BoolExtensions.AnyAreValueFalse(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.GreaterThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }

                        break;

                    case "<":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals;
                        }
                        else if (BoolExtensions.AnyAreValueTrue(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.LessThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.GreaterThan;
                        }

                        break;

                    case ">=":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (BoolExtensions.AnyAreValueFalse(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.GreaterThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }

                        break;

                    case "<=":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (BoolExtensions.AnyAreValueTrue(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.LessThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.GreaterThan;
                        }

                        break;
                    }

                    // right has the prefix, matching to left.  Right in general must be less than or equal to left

                    switch (version2.Prefix)
                    {
                    case "^":

                        if (version2.VersionTuple == version1.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (major1Greater.IsValueTrue())
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }
                        else if (majorMatch.IsValueTrue())
                        {
                            if (BoolExtensions.AnyAreValueTrue(patch1Greater, minor1Greater))
                            {
                                comparison = NpmVersionComparison.LessThan;
                            }
                            else if (BoolExtensions.AnyAreValueFalse(patch1Greater, minor1Greater))
                            {
                                comparison = NpmVersionComparison.GreaterThan | NpmVersionComparison.Matches;
                            }
                            else if (minorMatch.IsValueTrue())
                            {
                                comparison = NpmVersionComparison.Matches;
                            }
                            else
                            {
                                DebugUtils.Break();
                            }
                        }

                        break;

                    case "~":

                        if (version2.VersionTuple == version1.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (BoolExtensions.AnyAreValueTrue(major1Greater, minor1Greater))
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }
                        else if (BoolExtensions.AnyAreValueFalse(major1Greater, minor1Greater))
                        {
                            comparison = NpmVersionComparison.GreaterThan;
                        }
                        else if (minorMatch.IsValueTrue())
                        {
                            if (patch1Greater.IsValueTrue())
                            {
                                comparison = NpmVersionComparison.LessThan;
                            }
                            else if (patch1Greater.IsValueFalse())
                            {
                                comparison = NpmVersionComparison.GreaterThan | NpmVersionComparison.Matches;
                            }
                            else if (patchMatch.IsValueTrue())
                            {
                                comparison = NpmVersionComparison.Matches;
                            }
                            else
                            {
                                DebugUtils.Break();
                            }
                        }

                        break;

                    case ">":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals;
                        }
                        else if (BoolExtensions.AnyAreValueTrue(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.GreaterThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }

                        break;

                    case "<":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals;
                        }
                        else if (BoolExtensions.AnyAreValueFalse(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.LessThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.GreaterThan;
                        }

                        break;

                    case ">=":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (BoolExtensions.AnyAreValueTrue(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.GreaterThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.LessThan;
                        }

                        break;

                    case "<=":

                        if (version1.VersionTuple == version2.VersionTuple)
                        {
                            comparison = NpmVersionComparison.Equals | NpmVersionComparison.Matches;
                        }
                        else if (BoolExtensions.AnyAreValueFalse(major1Greater, minor1Greater, patch1Greater))
                        {
                            comparison = NpmVersionComparison.LessThan | NpmVersionComparison.Matches;
                        }
                        else
                        {
                            comparison = NpmVersionComparison.GreaterThan;
                        }

                        break;
                    }
                }
            }

            /*
             *  public enum NpmVersionComparison
             *  {
             *      NoComparison = 0,
             *      NotEquals = 1,
             *      Equals = 1 << 2,
             *      GreaterThan = 1 << 3,
             *      LessThan = 1 << 4,
             *      Matches = 1 << 5
             *  }
             */

            Debug.Assert(comparison != NpmVersionComparison.NoComparison);
            Debug.Assert(!(comparison.HasFlag(NpmVersionComparison.GreaterThan) && comparison.HasFlag(NpmVersionComparison.LessThan)));
            Debug.Assert(!(comparison.HasFlag(NpmVersionComparison.Equals) && comparison.HasFlag(NpmVersionComparison.NotEquals)));
            Debug.Assert(!(comparison.HasFlag(NpmVersionComparison.Equals) && comparison.HasFlag(NpmVersionComparison.GreaterThan)));
            Debug.Assert(!(comparison.HasFlag(NpmVersionComparison.Equals) && comparison.HasFlag(NpmVersionComparison.LessThan)));

            return(comparison);
        }
        public DataSet SBlocks(DataSet dataSet)
        {
            BitArray data = dataSet.Right;

            BitArray result             = new BitArray(32);
            BitArray OneBlockOutputData = new BitArray(4);

            int[] oneBlockInputData = new int[6];
            int[] rowBinNumber      = new int[2];

            int rowDecNumber = new int();

            int[] columnBinNumber = new int[4];
            int   columnDecNumber = new int();
            int   numberInBlock   = new int();

            int[,] blocks = { { 14,  4, 13,  1,  2, 15, 11,  8,  3, 10,  6, 12,  5,  9,  0,  7 },
                              {  0, 15,  7,  4, 14,  2, 13,  1, 10,  6, 12, 11,  9,  5,  3,  8 },
                              {  4,  1, 14,  8, 13,  6,  2, 11, 15, 12,  9,  7,  3, 10,  5,  0 },
                              { 15, 12,  8,  2,  4,  9,  1,  7,  5, 11,  3, 14, 10,  0,  6, 13 }, //S1

                              { 15,  1,  8, 14,  6, 11,  3,  4,  9,  7,  2, 13, 12,  0,  5, 10 },
                              {  3, 13,  4,  7, 15,  2,  8, 14, 12,  0,  1, 10,  6,  9, 11,  5 },
                              {  0, 14,  7, 11, 10,  4, 13,  1,  5,  8, 12,  6,  9,  3,  2, 15 },
                              { 13,  8, 10,  1,  3, 15,  4,  2, 11,  6,  7, 12,  0,  5, 14,  9 }, //S2

                              { 10,  0,  9, 14,  6,  3, 15,  5,  1, 13, 12,  7, 11,  4,  2,  8 },
                              { 13,  7,  0,  9,  3,  4,  6, 10,  2,  8,  5, 14, 12, 11, 15,  1 },
                              { 13,  6,  4,  9,  8, 15,  3,  0, 11,  1,  2, 12,  5, 10, 14,  7 },
                              {  1, 10, 13,  0,  6,  9,  8,  7,  4, 15, 14,  3, 11,  5,  2, 12 }, //S3

                              {  7, 13, 14,  3,  0,  6,  9, 10,  1,  2,  8,  5, 11, 12,  4, 15 },
                              { 13,  8, 11,  5,  6, 15,  0,  3,  4,  7,  2, 12,  1, 10, 14,  9 },
                              { 10,  6,  9,  0, 12, 11,  7, 13, 15,  1,  3, 14,  5,  2,  8,  4 },
                              {  3, 15,  0,  6, 10,  1, 13,  8,  9,  4,  5, 11, 12,  7,  2, 14 }, //S4

                              {  2, 12,  4,  1,  7, 10, 11,  6,  8,  5,  3, 15, 13,  0, 14,  9 },
                              { 14, 11,  2, 12,  4,  7, 13,  1,  5,  0, 15, 10,  3,  9,  8,  6 },
                              {  4,  2,  1, 11, 10, 13,  7,  8, 15,  9, 12,  5,  6,  3,  0, 14 },
                              { 11,  8, 12,  7,  1, 14,  2, 13,  6, 15,  0,  9, 10,  4,  5,  3 }, //S5

                              { 12,  1, 10, 15,  9,  2,  6,  8,  0, 13,  3,  4, 14,  7,  5, 11 },
                              { 10, 15,  4,  2,  7, 12,  9,  5,  6,  1, 13, 14,  0, 11,  3,  8 },
                              {  9, 14, 15,  5,  2,  8, 12,  3,  7,  0,  4, 10,  1, 13, 11,  6 },
                              {  4,  3,  2, 12,  9,  5, 15, 10, 11, 14,  1,  7,  6,  0,  8, 13 }, //S6

                              {  4, 11,  2, 14, 15,  0,  8, 13,  3, 12,  9,  7,  5, 10,  6,  1 },
                              { 13,  0, 11,  7,  4,  9,  1, 10, 14,  3,  5, 12,  2, 15,  8,  6 },
                              {  1,  4, 11, 13, 12,  3,  7, 14, 10, 15,  6,  8,  0,  5,  9,  2 },
                              {  6, 11, 13,  8,  1,  4, 10,  7,  9,  5,  0, 15, 14,  2,  3, 12 }, //S7

                              { 13,  2,  8,  4,  6, 15, 11,  1, 10,  9,  3, 14,  5,  0, 12,  7 },
                              {  1, 15, 13,  8, 10,  3,  7,  4, 12,  5,  6, 11,  0, 14,  9,  2 },
                              {  7, 11,  4,  1,  9, 12, 14,  2,  0,  6, 10, 13, 15,  3,  5,  8 },
                              {  2,  1, 14,  7,  4, 10,  8, 13, 15, 12,  9,  0,  3,  5,  6, 11 } //S8
            };

            for (int i = 0; i < 8; i++)
            {
                for (int j = 0; j < 6; j++)
                {
                    oneBlockInputData[j] = BoolExtensions.ToInt(data[j + 6 * i]);
                }

                rowBinNumber[0] = oneBlockInputData.First();
                rowBinNumber[1] = oneBlockInputData.Last();

                for (int j = 1; j <= 4; j++)
                {
                    columnBinNumber[j - 1] = oneBlockInputData[j];
                }


                rowDecNumber       = BinaryToDecimal(rowBinNumber);
                columnDecNumber    = BinaryToDecimal(columnBinNumber);
                OneBlockOutputData = new BitArray(new int[] { blocks[rowDecNumber + i * 4, columnDecNumber] });
                for (int j = 0; j < 4; j++)
                {
                    result[j + 4 * i] = OneBlockOutputData[3 - j];
                }
            }

            dataSet.Right = result;
            return(dataSet);
        }