public static void ConvertersTest()
 {
     using (var scope = new TempLinksTestScope())
     {
         const int N           = 10;
         var       links       = scope.Links;
         var       meaningRoot = links.CreatePoint();
         var       one         = links.CreateAndUpdate(meaningRoot, links.Constants.Itself);
         var       powerOf2ToUnaryNumberConverter = new PowerOf2ToUnaryNumberConverter <ulong>(links, one);
         var       toUnaryNumberConverter         = new AddressToUnaryNumberConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
         var       random       = new System.Random(0);
         ulong[]   numbers      = new ulong[N];
         ulong[]   unaryNumbers = new ulong[N];
         for (int i = 0; i < N; i++)
         {
             numbers[i]      = random.NextUInt64();
             unaryNumbers[i] = toUnaryNumberConverter.Convert(numbers[i]);
         }
         var fromUnaryNumberConverterUsingOrOperation  = new UnaryNumberToAddressOrOperationConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
         var fromUnaryNumberConverterUsingAddOperation = new UnaryNumberToAddressAddOperationConverter <ulong>(links, one);
         for (int i = 0; i < N; i++)
         {
             Assert.Equal(numbers[i], fromUnaryNumberConverterUsingOrOperation.Convert(unaryNumbers[i]));
             Assert.Equal(numbers[i], fromUnaryNumberConverterUsingAddOperation.Convert(unaryNumbers[i]));
         }
     }
 }
Exemplo n.º 2
0
 public static void CharAndUnaryNumberUnicodeSymbolConvertersTest()
 {
     using (var scope = new TempLinksTestScope())
     {
         var links       = scope.Links;
         var meaningRoot = links.CreatePoint();
         var one         = links.CreateAndUpdate(meaningRoot, links.Constants.Itself);
         var powerOf2ToUnaryNumberConverter = new PowerOf2ToUnaryNumberConverter <ulong>(links, one);
         var addressToUnaryNumberConverter  = new AddressToUnaryNumberConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
         var unaryNumberToAddressConverter  = new UnaryNumberToAddressOrOperationConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
         TestCharAndUnicodeSymbolConverters(links, meaningRoot, addressToUnaryNumberConverter, unaryNumberToAddressConverter);
     }
 }
Exemplo n.º 3
0
        public static void StringAndUnicodeSequenceConvertersTest()
        {
            using (var scope = new TempLinksTestScope())
            {
                var links = scope.Links;

                var itself = links.Constants.Itself;

                var meaningRoot             = links.CreatePoint();
                var unaryOne                = links.CreateAndUpdate(meaningRoot, itself);
                var unicodeSymbolMarker     = links.CreateAndUpdate(meaningRoot, itself);
                var unicodeSequenceMarker   = links.CreateAndUpdate(meaningRoot, itself);
                var frequencyMarker         = links.CreateAndUpdate(meaningRoot, itself);
                var frequencyPropertyMarker = links.CreateAndUpdate(meaningRoot, itself);

                var powerOf2ToUnaryNumberConverter = new PowerOf2ToUnaryNumberConverter <ulong>(links, unaryOne);
                var addressToUnaryNumberConverter  = new AddressToUnaryNumberConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
                var charToUnicodeSymbolConverter   = new CharToUnicodeSymbolConverter <ulong>(links, addressToUnaryNumberConverter, unicodeSymbolMarker);

                var unaryNumberToAddressConverter = new UnaryNumberToAddressOrOperationConverter <ulong>(links, powerOf2ToUnaryNumberConverter);
                var unaryNumberIncrementer        = new UnaryNumberIncrementer <ulong>(links, unaryOne);
                var frequencyIncrementer          = new FrequencyIncrementer <ulong>(links, frequencyMarker, unaryOne, unaryNumberIncrementer);
                var frequencyPropertyOperator     = new PropertyOperator <ulong>(links, frequencyPropertyMarker, frequencyMarker);
                var index = new FrequencyIncrementingSequenceIndex <ulong>(links, frequencyPropertyOperator, frequencyIncrementer);
                var linkToItsFrequencyNumberConverter        = new LinkToItsFrequencyNumberConveter <ulong>(links, frequencyPropertyOperator, unaryNumberToAddressConverter);
                var sequenceToItsLocalElementLevelsConverter = new SequenceToItsLocalElementLevelsConverter <ulong>(links, linkToItsFrequencyNumberConverter);
                var optimalVariantConverter = new OptimalVariantConverter <ulong>(links, sequenceToItsLocalElementLevelsConverter);

                var stringToUnicodeSequenceConverter = new StringToUnicodeSequenceConverter <ulong>(links, charToUnicodeSymbolConverter, index, optimalVariantConverter, unicodeSequenceMarker);

                var originalString = "Hello";

                var unicodeSequenceLink = stringToUnicodeSequenceConverter.Convert(originalString);

                var unicodeSymbolCriterionMatcher = new TargetMatcher <ulong>(links, unicodeSymbolMarker);
                var unicodeSymbolToCharConverter  = new UnicodeSymbolToCharConverter <ulong>(links, unaryNumberToAddressConverter, unicodeSymbolCriterionMatcher);

                var unicodeSequenceCriterionMatcher = new TargetMatcher <ulong>(links, unicodeSequenceMarker);

                var sequenceWalker = new LeveledSequenceWalker <ulong>(links, unicodeSymbolCriterionMatcher.IsMatched);

                var unicodeSequenceToStringConverter = new UnicodeSequenceToStringConverter <ulong>(links, unicodeSequenceCriterionMatcher, sequenceWalker, unicodeSymbolToCharConverter);

                var resultingString = unicodeSequenceToStringConverter.Convert(unicodeSequenceLink);

                Assert.Equal(originalString, resultingString);
            }
        }