Exemplo n.º 1
0
        public void TestSerializingSimpleHypergrid()
        {
            string originalValidSimpleHypergridJsonString = PythonScriptsAndJsons.SpinlockSearchSpaceJson;

            Hypergrid spinlockSearchSpace = new Hypergrid(
                "SpinlockSearchSpace",
                new DiscreteDimension(name: "shortBackOffMilliSeconds", min: 1, max: 1 << 20),
                new DiscreteDimension(name: "longBackOffMilliSeconds", min: 1, max: 1 << 20),
                new DiscreteDimension(name: "longBackOffWaitMilliSeconds", min: 1, max: 1 << 20),
                new DiscreteDimension(name: "minSpinCount", min: 1, max: 1 << 20),
                new DiscreteDimension(name: "maxSpinCount", min: 1, max: 1 << 20),
                new DiscreteDimension(name: "maxbackOffAttempts", min: 1, max: 1 << 20),
                new DiscreteDimension(name: "acquireSpinCount", min: 1, max: 1 << 20),
                new CategoricalDimension(name: "algorithm", values: new[] { "Optimistic", "ExponentialBackoff" }));
            var jsonSerializerOptions = new JsonSerializerOptions
            {
                WriteIndented = true,
                Converters    =
                {
                    new JsonStringEnumConverter(),
                    new HypergridJsonConverter(),
                    new DimensionJsonConverter(),
                },
            };

            string serializedJsonString = JsonSerializer.Serialize(spinlockSearchSpace, jsonSerializerOptions);

            Assert.Equal(originalValidSimpleHypergridJsonString, serializedJsonString);

            string yetAnotherSerializedJsonString = spinlockSearchSpace.ToJson();

            Assert.Equal(originalValidSimpleHypergridJsonString, yetAnotherSerializedJsonString);
        }
Exemplo n.º 2
0
        public void TestNewConverter()
        {
            JsonSerializerOptions options = new JsonSerializerOptions
            {
                WriteIndented = true,
                Converters    =
                {
                    new HypergridJsonConverter(),
                    new DimensionJsonConverter(),
                },
            };

            var    json = JsonSerializer.Serialize <Hypergrid>(allKindsOfDimensions, options);
            string serializedHypergrid = allKindsOfDimensions.ToJson();

            var deserializedSimpleHypergrid = JsonSerializer.Deserialize <Hypergrid>(serializedHypergrid, options);
        }