public void ConvertFromVectorBaseToGuidBackToVectorBase()
        {
            // CV bases which have four zero least significant bits meaning a conversion to a Guid will retain all
            // information.
            // CV Base -> Guid -> CV Base conversions result in:
            //   /////////////////////A -> ffffffff-ffff-ffff-ffff-fffffffffffc -> /////////////////////A
            //   /////////////////////Q -> ffffffff-ffff-ffff-ffff-fffffffffffd -> /////////////////////Q
            //   /////////////////////g -> ffffffff-ffff-ffff-ffff-fffffffffffe -> /////////////////////g
            //   /////////////////////w -> ffffffff-ffff-ffff-ffff-ffffffffffff -> /////////////////////w
            string[] validGuidVectorBases = new string[]
            {
                "/////////////////////A",
                "/////////////////////Q",
                "/////////////////////g",
                "/////////////////////w",
            };

            foreach (string vectorBase in validGuidVectorBases)
            {
                var  correlationVector         = CorrelationVector.Parse($"{vectorBase}.0");
                Guid baseAsGuid                = correlationVector.GetBaseAsGuid();
                var  correlationVectorFromGuid = new CorrelationVectorV2(baseAsGuid);

                Assert.AreEqual(correlationVector.Value, correlationVectorFromGuid.Value,
                                $"Correlation vector base -> guid -> correlation vector base should result in the same vector base for {vectorBase}");
            }
        }
        public void ParseCorrelationVectorV1Test()
        {
            var correlationVector = CorrelationVector.Parse("ifCuqpnwiUimg7Pk.1");
            var splitVector       = correlationVector.Value.Split('.');

            Assert.AreEqual("ifCuqpnwiUimg7Pk", splitVector[0], "Correlation Vector base was not parsed properly");
            Assert.AreEqual("1", splitVector[1], "Correlation Vector extension was not parsed properly");
        }
        public void ParseCorrelationVectorV2Test()
        {
            var correlationVector = CorrelationVector.Parse("Y58xO9ov0kmpPvkiuzMUVA.3.4.5");
            var splitVector       = correlationVector.Value.Split('.');

            Assert.AreEqual(4, splitVector.Length, "Correlation Vector was not parsed properly");
            Assert.AreEqual("Y58xO9ov0kmpPvkiuzMUVA", splitVector[0], "Correlation Vector base was not parsed properly");
            Assert.AreEqual("3", splitVector[1], "Correlation Vector extension was not parsed properly");
            Assert.AreEqual("4", splitVector[2], "Correlation Vector extension was not parsed properly");
            Assert.AreEqual("5", splitVector[3], "Correlation Vector extension was not parsed properly");
        }
        public void GetBaseAsGuidForInvalidGuidVectorBaseTest()
        {
            // CV base which has four non-zero least significant bits meaning conversion to Guid will lose information.
            // CV Base -> Guid -> CV Base conversion results in:
            //   /////////////////////B -> ffffffff-ffff-ffff-ffff-fffffffffffc -> /////////////////////A
            string vectorBase     = "/////////////////////B";
            Guid   vectorBaseGuid = Guid.Parse("ffffffff-ffff-ffff-ffff-fffffffffffc");

            try
            {
                var correlationVector = CorrelationVector.Parse($"{vectorBase}.0");

                CorrelationVector.ValidateCorrelationVectorDuringCreation = false;
                Guid baseAsGuid = correlationVector.GetBaseAsGuid();
                Assert.AreEqual(vectorBaseGuid, baseAsGuid, "Correlation Vector base as a guid should be the same as the expected guid");

                CorrelationVector.ValidateCorrelationVectorDuringCreation = true;
                Assert.ThrowsException <InvalidOperationException>(() => correlationVector.GetBaseAsGuid());
            }
            finally
            {
                CorrelationVector.ValidateCorrelationVectorDuringCreation = false;
            }
        }
Exemple #5
0
 public CorrelationVectorFeature(string correlationVector)
 {
     CV = CorrelationVector.Parse(correlationVector);
 }