Example #1
0
        void MakeSwitchFuncs()
        {
            var combo = new StringBuilder();

            foreach (var keyPair in KeyPairRepository.KeyPairsForKeyCount(KeyCount))
            {
                combo.AppendLine(SwitchMaskDefinition(SwitchableDataType.Name, keyPair));
            }
            Session.Execute(combo.ToString());
            combo.Clear();

            for (var i = 0; i < KeyCount; i++)
            {
                combo.AppendLine(ShiftDefinition(SwitchableDataType.Name, i));
            }
            Session.Execute(combo.ToString());
            combo.Clear();

            combo.AppendLine(String.Format("new Func<{0}, Tuple<{0}, bool>>[] {{", SwitchableDataType.Name));
            foreach (var keyPair in KeyPairRepository.KeyPairsForKeyCount(KeyCount))
            {
                combo.AppendLine((keyPair.Index == 0) ? string.Empty : ",");
                combo.AppendLine(SwitchExpression(SwitchableDataType.Name, keyPair));
            }
            combo.AppendLine("}");

            //System.Diagnostics.Debug.WriteLine(combo.ToString());
            _switchFuncs = (Func <T, Tuple <T, bool> >[])Session.Execute(combo.ToString());
        }
Example #2
0
        public void TestIntArraySwitchSetFunctionsAreNotNull()
        {
            var keyCount          = 7;
            var intArraySwitchSet = KeyPairSwitchSet.Make <int[]>(keyCount);

            var keyPairs = KeyPairRepository.KeyPairsForKeyCount(keyCount).ToList();

            foreach (var keyPair in keyPairs)
            {
                Assert.IsNotNull(intArraySwitchSet.SwitchFunction(keyPair));
            }

            keyCount          = 16;
            intArraySwitchSet = KeyPairSwitchSet.Make <int[]>(keyCount);

            keyPairs = KeyPairRepository.KeyPairsForKeyCount(keyCount).ToList();
            foreach (var keyPair in keyPairs)
            {
                Assert.IsNotNull(intArraySwitchSet.SwitchFunction(keyPair));
            }

            keyCount          = 33;
            intArraySwitchSet = KeyPairSwitchSet.Make <int[]>(keyCount);

            keyPairs = KeyPairRepository.KeyPairsForKeyCount(keyCount).ToList();
            foreach (var keyPair in keyPairs)
            {
                Assert.IsNotNull(intArraySwitchSet.SwitchFunction(keyPair));
            }
        }
 public void TestKeyPairsCount()
 {
     Assert.AreEqual
     (
         KeyPairRepository.KeyPairsForKeyCount(KeyPairRepository.MaxKeyCount).Count(),
         KeyPairRepository.KeyPairSetSizeForKeyCount(KeyPairRepository.MaxKeyCount)
     );
 }
 public void TestKeyPairAssignment()
 {
     foreach (var keyPair in KeyPairRepository.KeyPairsForKeyCount(KeyPairRepository.MaxKeyCount))
     {
         Assert.AreEqual
         (
             keyPair.Index,
             KeyPairRepository.KeyPairIndex(keyPair.LowKey, keyPair.HiKey)
         );
     }
 }
        void MakeSwitchFuncs()
        {
            var returnValueType = string.Format("Tuple<{0}, bool>", SwitchableDataType.Name);

            foreach (var keyPair in KeyPairRepository.KeyPairsForKeyCount(KeyCount).ToList())
            {
                var strInitializer = string.Format(
                    "new Func<{0}, {1}>(a => (a[{3}]{2}a[{4}]) ? new {1}({5}, true) : new {1}(a, false))",
                    SwitchableDataType.Name,
                    returnValueType,
                    OperatorName,
                    keyPair.LowKey,
                    keyPair.HiKey,
                    ArrayBuilder("a", keyPair, KeyCount)
                    );

                _switchFuncs[keyPair.Index] = (Func <T, Tuple <T, bool> >)Session.Execute(strInitializer);
            }
        }
Example #6
0
        public void TestBitArraySwitchSetFunctionsSwitchTheRightIndexes()
        {
            var keyCount          = 64;
            var bitArraySwitchSet = KeyPairSwitchSet.Make <bool[]>(keyCount);

            var keyPairs = KeyPairRepository.KeyPairsForKeyCount(keyCount).ToList();

            foreach (var keyPair in keyPairs)
            {
                var preSwitch  = BitArrayUtils.SetTrueBitInArray(keyPair.LowKey, keyCount);
                var postSwitch = BitArrayUtils.SetTrueBitInArray(keyPair.HiKey, keyCount);

                var switchResult = bitArraySwitchSet.SwitchFunction(keyPair)(preSwitch);
                Assert.IsTrue(switchResult.Item2);
                Assert.AreEqual(0, postSwitch.CompareDict(switchResult.Item1));

                Assert.IsNotNull(bitArraySwitchSet.SwitchFunction(keyPair));
            }
        }
Example #7
0
        public void TestIntArraySwitchSetFunctionsSwitchTheRightIndexes()
        {
            var keyCount          = 7;
            var intArraySwitchSet = KeyPairSwitchSet.Make <int[]>(keyCount);

            var keyPairs = KeyPairRepository.KeyPairsForKeyCount(keyCount).ToList();

            foreach (var keyPair in keyPairs)
            {
                var preSwitch = new int[keyCount];
                preSwitch[keyPair.LowKey] = 33;
                var postSwitch = new int[keyCount];
                postSwitch[keyPair.HiKey] = 33;

                var switchResult = intArraySwitchSet.SwitchFunction(keyPair)(preSwitch);
                Assert.IsTrue(switchResult.Item2);
                Assert.AreEqual(0, postSwitch.CompareDict(switchResult.Item1));

                Assert.IsNotNull(intArraySwitchSet.SwitchFunction(keyPair));
            }
        }