private static ParameterSet ConvertToParameterSet(TlcModule.SweepableParamAttribute[] hps,
                                                          RecipeInference.SuggestedRecipe.SuggestedLearner learner)
        {
            if (learner.PipelineNode.HyperSweeperParamSet != null)
            {
                return(learner.PipelineNode.HyperSweeperParamSet);
            }

            var paramValues = new IParameterValue[hps.Length];

            if (hps.Any(p => p.RawValue == null))
            {
                PopulateSweepableParams(learner);
            }

            for (int i = 0; i < hps.Length; i++)
            {
                Contracts.CheckValue(hps[i].RawValue, nameof(TlcModule.SweepableParamAttribute.RawValue));

                switch (hps[i])
                {
                case TlcModule.SweepableDiscreteParamAttribute dp:
                    var learnerVal =
                        learner.PipelineNode.GetPropertyValueByName(dp.Name, (IComparable)dp.Options[0]);
                    var optionIndex = (int)(dp.RawValue ?? dp.IndexOf(learnerVal));
                    paramValues[i] = new StringParameterValue(dp.Name, dp.Options[optionIndex].ToString());
                    break;

                case TlcModule.SweepableFloatParamAttribute fp:
                    paramValues[i] =
                        new FloatParameterValue(fp.Name,
                                                (float)(fp.RawValue ?? learner.PipelineNode.GetPropertyValueByName(fp.Name, 0f)));
                    break;

                case TlcModule.SweepableLongParamAttribute lp:
                    paramValues[i] =
                        new LongParameterValue(lp.Name,
                                               (long)(lp.RawValue ?? learner.PipelineNode.GetPropertyValueByName(lp.Name, 0L)));
                    break;
                }
            }

            learner.PipelineNode.HyperSweeperParamSet = new ParameterSet(paramValues);
            return(learner.PipelineNode.HyperSweeperParamSet);
        }
        public void TestLongValueGeneratorRoundTrip()
        {
            var paramSweep = new LongValueGenerator(new LongParamArguments()
            {
                Name = "bla", Min = 0, Max = 17
            });
            var             value             = new LongParameterValue("bla", 5);
            float           normalizedValue   = paramSweep.NormalizeValue(value);
            IParameterValue unNormalizedValue = paramSweep.CreateFromNormalized(normalizedValue);

            Assert.Equal("5", unNormalizedValue.ValueText);

            IParameterValue param             = paramSweep.CreateFromNormalized(0.345);
            float           unNormalizedParam = paramSweep.NormalizeValue(param);

            Assert.Equal("5", param.ValueText);
            Assert.Equal((float)5 / 17, unNormalizedParam);
        }
        public void TestLongParameterValue()
        {
            LongParameterValue value1          = new LongParameterValue(nameof(value1), 1);
            LongParameterValue value2          = new LongParameterValue(nameof(value2), 2);
            LongParameterValue duplicateValue1 = new LongParameterValue(nameof(value1), 1);

            Assert.False(value1.Equals(value2));
            Assert.True(value1.Equals(value1));
            Assert.True(value1.Equals(duplicateValue1));
            Assert.False(value1.Equals((object)value2));
            Assert.True(value1.Equals((object)value1));
            Assert.True(value1.Equals((object)duplicateValue1));

            Assert.False(value1.Equals(new FloatParameterValue(nameof(value1), 1.0f)));
            Assert.False(value1.Equals((IParameterValue)null));
            Assert.False(value1.Equals((object)null));
            Assert.False(value1.Equals(new object()));

            Assert.Equal(value1.GetHashCode(), value1.GetHashCode());
            Assert.Equal(value1.GetHashCode(), duplicateValue1.GetHashCode());
        }
        public void TestParameterSetEquality()
        {
            LongParameterValue   value1       = new LongParameterValue(nameof(value1), 1);
            LongParameterValue   value2       = new LongParameterValue(nameof(value2), 2);
            StringParameterValue stringValue1 = new StringParameterValue(nameof(value1), "1");

            var parameterSet = new ParameterSet(new[] { value1 });

            Assert.False(parameterSet.Equals(null));

            // Verify Equals for sets with different hash codes
            var parameterSetNewHash = new ParameterSet(new IParameterValue[] { value1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode() + 1);

            Assert.NotEqual(parameterSet.GetHashCode(), parameterSetNewHash.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetNewHash));

            // Verify Equals for sets with the same hash code, but different number of values
            var parameterSetMoreValues = new ParameterSet(new IParameterValue[] { value1, value2 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetMoreValues.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetMoreValues));

            // Verify Equals for sets with the same hash and item counts, but one of the items has a different name
            var parameterSetDifferentName = new ParameterSet(new IParameterValue[] { value2 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetDifferentName.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetDifferentName));

            // Verify Equals for sets with the same hash and item names, but one of the items has a different value
            var parameterSetDifferentValue = new ParameterSet(new IParameterValue[] { stringValue1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetDifferentValue.GetHashCode());
            Assert.False(parameterSet.Equals(parameterSetDifferentValue));

            // Verify Equals for sets with the same hash and items
            var parameterSetSameHash = new ParameterSet(new IParameterValue[] { value1 }.ToDictionary(x => x.Name), hash: parameterSet.GetHashCode());

            Assert.Equal(parameterSet.GetHashCode(), parameterSetSameHash.GetHashCode());
            Assert.True(parameterSet.Equals(parameterSetSameHash));
        }