Exemplo n.º 1
0
        public void CanConvertToFromFeature()
        {
            Feature feature1 = new Feature();

            feature1.Add(0, 0);
            feature1.Add(1, 0);
            feature1.Add(2, 0);

            FeatureAsset featureAsset1 = FeatureAsset.FromFeature(feature1);
            Feature      testFeature1  = featureAsset1.ToFeature();

            // Basic test. All input positions should be present in output
            Assert.Contains(new Vector2Int(0, 0), testFeature1.Elements.Keys);
            Assert.Contains(new Vector2Int(1, 0), testFeature1.Elements.Keys);
            Assert.Contains(new Vector2Int(2, 0), testFeature1.Elements.Keys);

            // Basic test. Ensure bounds are unchanged
            Assert.AreEqual(feature1.MaxX, testFeature1.MaxX);
            Assert.AreEqual(feature1.MaxY, testFeature1.MaxY);
            Assert.AreEqual(feature1.MinX, testFeature1.MinX);
            Assert.AreEqual(feature1.MinY, testFeature1.MinY);


            // Harder test. Conversion of Feature -> FeatureAsset -> Feature does not obey identity property.
            // All connections at the end will be present in the original, but additionally,
            // they will be restricted based on FeatureAsset retention rules.
            //
            // Thus, we test FeatureAsset retention rules separately, and ensure that
            // FeatureAfter.connections & FeatureBefore.connections == FeatureAfter.connections
            // to be sure that no connections are ever dropped.
            foreach (KeyValuePair <Vector2Int, Labrys.Generation.Section> kvp in testFeature1.Elements)
            {
                Labrys.Generation.Section orig = feature1.Elements[kvp.Key];
                Labrys.Generation.Section conv = kvp.Value;

                // Some connections may be lost. Ensure no new ones are added.
                Assert.AreEqual(orig.externalConnections & conv.externalConnections, conv.externalConnections);
                Assert.AreEqual(orig.internalConnections & conv.internalConnections, conv.internalConnections);

                // Make sure variants are unchanged.
                Assert.AreEqual(orig.GetVariant(), conv.GetVariant());
            }
        }