Пример #1
0
 public void TestKeyPairsCount()
 {
     Assert.AreEqual
     (
         KeyPairRepository.KeyPairsForKeyCount(KeyPairRepository.MaxKeyCount).Count(),
         KeyPairRepository.KeyPairSetSizeForKeyCount(KeyPairRepository.MaxKeyCount)
     );
 }
        public void ConvertSorterTest()
        {
            const int keyCount       = 16;
            const int sequenceLength = 100;
            var       keyPairSet     = KeyPairRepository.KeyPairSet(keyCount);

            var guid     = Guid.NewGuid();
            var keyPairs = Enumerable.Range(0, KeyPairRepository.KeyPairSetSizeForKeyCount(keyCount))
                           .Select(i => keyPairSet[i])
                           .ToArray();

            var sorter = keyPairs.ToSorter(guid: guid, keyCount: keyCount);

            var serialized = JsonConvert.SerializeObject(sorter.ToJsonAdapter(), Formatting.Indented);
            var newSorter  = serialized.ToSorter();

            Assert.AreEqual(newSorter.Guid, guid);
            Assert.AreEqual(newSorter.KeyCount, keyCount);
            Assert.IsTrue(newSorter.KeyPairs.IsSameAs(keyPairs));
        }
Пример #3
0
        public static ISorterGenome ToSorterGenome(
            this IRando randy,
            int keyCount,
            int keyPairCount)
        {
            var keyPairSetSize = (uint)KeyPairRepository.KeyPairSetSizeForKeyCount(keyCount);

            return(new SorterGenomeImpl
                   (
                       guid: randy.NextGuid(),
                       parentGuid: Guid.Empty,
                       chromosome: randy
                       .ToUintEnumerator(keyPairSetSize)
                       .Take(keyPairCount)
                       .ToList()
                       .ToChromosomeUint
                       (
                           maxVal: keyPairSetSize
                       ),
                       keyCount: keyCount,
                       keyPairCount: keyPairCount
                   ));
        }
Пример #4
0
 protected void OnConvertToGenomesCommand()
 {
     foreach (var sorterVm in SorterGridVm.SorterVms)
     {
         SorterGenomeGridVm.SorterGenomeVms.Add
         (
             new SorterGenomeVm
             (
                 SorterGenome.Make
                 (
                     guid: sorterVm.Guid,
                     parentGuid: Guid.Empty,
                     chromosome: ChromosomeUint.Make
                     (
                         sequence: sorterVm.Sorter.KeyPairs.Select(kp => (uint)kp.Index).ToArray(),
                         maxVal: (uint)KeyPairRepository.KeyPairSetSizeForKeyCount(sorterVm.Sorter.KeyCount)
                     ),
                     keyCount: sorterVm.Sorter.KeyCount,
                     keyPairCount: sorterVm.Sorter.KeyPairCount
                 )
             )
         );
     }
 }
Пример #5
0
 protected ArraySwitchSet(int keyCount)
 {
     _keyCount    = keyCount;
     _switchFuncs = new  Func <T, Tuple <T, bool> > [KeyPairRepository.KeyPairSetSizeForKeyCount(KeyCount)];
     MakeSwitchFuncs();
 }