예제 #1
0
        internal PairwiseComparisonTerm(PairwiseComparison comparison, PairwiseParameter left, PairwiseParameter rightParam, PairwiseValue rightVal) : base(left)
        {
            if (rightVal == null && rightParam == null)
            {
                throw new ArgumentException("Can't have both val and param == null!");
            }

            if (rightVal != null && rightParam != null)
            {
                throw new ArgumentException("Can't have both val and param non-null!");
            }

            if (left == rightParam)
            {
                throw new ArgumentException("Can't have the same two parameters in the same comparison");
            }

            this.rel          = comparison;
            this.rhsValue     = rightVal;
            this.rhsParameter = rightParam;
            if (rightVal != null && !this.Parameter.IsCompatibleWith(rightVal))
            {
                throw new ArgumentException(string.Format("Mismatched types: {0} != {1}", left.PairwiseValueType, rightVal.PairwiseValueType));
            }

            if (rightParam != null && !this.Parameter.IsCompatibleWith(rightParam))
            {
                throw new ArgumentException(string.Format("Mismatched types: {0} != {1}", left.PairwiseValueType, rightParam.PairwiseValueType));
            }

            if (!this.Parameter.IsCompatibleWith(rel))
            {
                throw new NotSupportedException("Not supported: " + rel + " on " + this.Parameter + "; might be possible, though!");
            }
        }
예제 #2
0
        // warning: slow
        public PairwiseValue this[Type t]
        {
            get
            {
                PairwiseValue match = null;

                foreach (PairwiseValue v in this.values)
                {
                    if (v.ValueType == t)
                    {
                        if (match != null)
                        {
                            throw new ArgumentException("Type " + t + " occurred multiple times");
                        }

                        match = v;
                    }
                }

                if (match != null)
                {
                    return(match);
                }
                else
                {
                    throw new IndexOutOfRangeException(t.FullName + " not found");
                }
            }
        }
예제 #3
0
 public PairwiseParameter(string name, string[] values)
 {
     this.name = name;
     foreach (string s in values)
     {
         this.AddValue(PairwiseValue.FromString(s));
     }
 }
예제 #4
0
        public bool Contains(PairwiseValue value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return(InnerList.Contains(value));
        }
예제 #5
0
        public static PairwiseValue CreateNegativeOption(PairwiseValue value)
        {
            if (value.IsNegative)
            {
                throw new ArgumentException(value + " already negative");
            }

            return(CreateNegativeOption(value.value));
        }
예제 #6
0
        public void Insert(int index, PairwiseValue value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            InnerList.Insert(index, value);
        }
예제 #7
0
        public void Remove(PairwiseValue value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            InnerList.Remove(value);
        }
예제 #8
0
        public int Add(PairwiseValue value)
        {
            if (value == null)
            {
                throw new ArgumentNullException("value");
            }

            return(InnerList.Add(value));
        }
예제 #9
0
 internal int Add(string name, PairwiseValue value)
 {
     Debug.Assert(value != null);
     Debug.Assert(name != null);
     ++last;
     Debug.Assert(names[last] == name);
     values[last] = value;
     isNegative   = isNegative || value.IsNegative;
     return(last);
 }
예제 #10
0
        protected override void OnValidate(object value)
        {
            base.OnValidate(value);

            PairwiseValue pvalue = value as PairwiseValue;

            if (pvalue == null)
            {
                throw new ArgumentException("PairwiseValue");
            }
        }
예제 #11
0
 string Quoted(PairwiseValue value)
 {
     if (value.PairwiseValueType == PairwiseValueType.Number)
     {
         return(context.LookupOutputValue(value));
     }
     else
     {
         return('"' + context.LookupOutputValue(value) + '"');
     }
 }
예제 #12
0
        internal bool IsCompatibleWith(PairwiseValue value)
        {
            if (value == null)
            {
                return(false);
            }

            if (!setFirstType)
            {
                return(true);
            }

            return(this.PairwiseValueType == value.PairwiseValueType);
        }
예제 #13
0
        // Rule support
        public PairwiseValue AddValue(PairwiseValue value)
        {
            if (!setFirstType)
            {
                firstType    = value.PairwiseValueType;
                setFirstType = true;
            }

            if (value.PairwiseValueType != firstType)
            {
                throw new PairwiseException(string.Format("Type mismatch: {0} != {1}", this.firstType, value.ValueType, firstType));
            }

            valueCollection.Add(value);
            return(value);
        }
예제 #14
0
        public PairwiseTuple[] Generate(out PictExecutionInformation executionInformation)
        {
            string[][] results;
            string     pictModel = (string)this.Visit(model);

            // PictConstants.Trace("Pict model: {0}", model.Comment);
            string fn = settings.CanCache ? PictConstants.CacheFileName : null;

            using (PictRunner exec = new PictRunner(fn))
            {
                results = exec.MaybeExecutePict(settings, pictModel);
                executionInformation = exec.LastExecutionInformation;
                if (settings.RandomizeGeneration)
                {
                    settings.RandomSeed = executionInformation.RandomSeed;
                    // NOTE: not setting settings.RandomSeedSpecified
                }
            }

            // PictConstants.Trace("Results of executing PICT: {0}", results.Substring(0, Math.Min(255, results.Length)));
            int tupleLen = results[0].Length;

            PairwiseTuple[] tuples = new PairwiseTuple[results.Length - 1]; // skip the header
            string[]        fields = results[0];

            for (int tupleNumber = 0; tupleNumber < tuples.Length; ++tupleNumber)
            {
                // the line we access is actually '1-indexed': the first row is the fields
                string[]      line = results[tupleNumber + 1];
                PairwiseTuple pt   = new PairwiseTuple(fields);

                for (int currentField = 0; currentField < tupleLen; ++currentField)
                {
                    PairwiseValue value = context.FindValue(currentField, line[currentField]);

                    pt.Add(model.Parameters[currentField].Name, value);
                }

                tuples[tupleNumber] = pt;
            }

            return(tuples);
        }
예제 #15
0
        public override bool Equals(object obj)
        {
            PairwiseValue opt = obj as PairwiseValue;

            if (opt == null)
            {
                return(false); // throw?
            }

            if (opt == this)
            {
                return(true);
            }

            // note: considering negative but not weights or aliases
            return((opt.isNegative == this.isNegative) && //
                   (opt.ValueType == this.ValueType) &&   //
                   object.Equals(opt.value, this.value));
        }
예제 #16
0
        protected override void OnValidate(object val)
        {
            base.OnValidate(val);
            if (val == null)
            {
                throw new ArgumentNullException("value");
            }

            PairwiseValue value = val as PairwiseValue;

            if (value == null)
            {
                throw new ArgumentException("Not a PairwiseValue, was a " + value.GetType().FullName);
            }

            if (value.ValueType != parent.ValueType)
            {
                throw new ArgumentException("Was a " + value.ValueType + "; expected " + parent.ValueType);
            }

            if (value.IsNegative != parent.IsNegative)
            {
                throw new ArgumentException(value + " IsNegative = " + value.IsNegative + " but expected " + parent.IsNegative);
            }

            // TBD: is this allowable?
            if (value.Aliases.Count != 0)
            {
                throw new ArgumentException("Attempted to do nested aliases: " + value.Aliases.Count + " present");
            }

            if (this.Contains(value))
            {
                throw new ArgumentException("Already contains " + value);
            }

            if (value.PairwiseValueType == PairwiseValueType.ComplexObject)
            {
                throw new NotSupportedException("Complex type comparison not yet supported");
            }
        }
예제 #17
0
        // NOTE: for PICT 3.0.34.0, the negative aliases are double-~'d, so we don't put them when we build the alias list
        public string LookupValuesAndAliases(PairwiseValue value)
        {
            if (value.Aliases.Count == 0)
            {
                return(LookupOutputValue(value));
            }

            StringBuilder sb = new StringBuilder(100 + (20 * value.Aliases.Count));

            sb.Append(LookupOutputValueWithoutWeight(value));
            for (int i = 0, nminus1 = value.Aliases.Count - 1; i < value.Aliases.Count; ++i)
            {
                PairwiseValue alias = value.Aliases[i];

                sb.Append(settings.AliasDelimiter);

                string q;

                if (i == nminus1)
                {
                    // get the weight from the first value, not the second!
                    q = LookupOutputValueWithWeight(alias, value.Weight);
                }
                else
                {
                    q = LookupOutputValueWithoutWeight(alias);
                }

                if (q.StartsWith(settings.NegativePrefixString))
                {
                    // q = q.Substring(PictConstants.NegativeValuePrefixString.Length);
                    sb.Append(q, settings.NegativePrefixString.Length, q.Length - settings.NegativePrefixString.Length);
                }
                else
                {
                    sb.Append(q);
                }
            }

            return(sb.ToString());
        }
예제 #18
0
 public void Insert(int index, PairwiseValue value)
 {
     List.Insert(index, value);
 }
예제 #19
0
 public string LookupInputValue(PairwiseValue valuex)
 {
     return(LookupWork(valuex, false, valuex.Weight));
 }
예제 #20
0
 public PairwiseLessThanTerm(PairwiseParameter parameter, PairwiseValue value) : base(PairwiseComparison.LessThan, parameter, null, value)
 {
 }
예제 #21
0
 public string LookupOutputValue(PairwiseValue valuex)
 {
     return(LookupWork(valuex, true, valuex.Weight));
 }
예제 #22
0
 string LookupOutputValueWithWeight(PairwiseValue valuex, int weight)
 {
     return(LookupWork(valuex, true, weight));
 }
예제 #23
0
 public PairwiseNotEqualTerm NotEqual(PairwiseValue value)
 {
     return(new PairwiseNotEqualTerm(this, value));
 }
예제 #24
0
 public PairwiseLessThanOrEqualTerm LessThanOrEqual(PairwiseValue value)
 {
     return(new PairwiseLessThanOrEqualTerm(this, value));
 }
예제 #25
0
 public PairwiseLessThanTerm LessThan(PairwiseValue value)
 {
     return(new PairwiseLessThanTerm(this, value));
 }
예제 #26
0
 public PairwiseGreaterThanOrEqualTerm GreaterThanOrEqual(PairwiseValue value)
 {
     return(new PairwiseGreaterThanOrEqualTerm(this, value));
 }
예제 #27
0
 public int IndexOf(PairwiseValue value)
 {
     return(List.IndexOf(value));
 }
예제 #28
0
 public void RemoveValue(PairwiseValue value)
 {
     valueCollection.Remove(value);
 }
예제 #29
0
        string LookupWork(PairwiseValue valuex, bool includeWeight, int weight)
        {
            string v;
            object vv = valuex.Value;

            switch (valuex.PairwiseValueType)
            {
            case PairwiseValueType.Enum:
                v = PictConstants.AggressivelyEscape(vv.ToString().Replace(',', ';'));
                break;

            case PairwiseValueType.String:
                //
                v = PictConstants.AggressivelyEscape(vv.ToString());
                break;

            case PairwiseValueType.Number:
                // NOTE: here we fixed the german issue
                if (valuex.ValueType == typeof(Char))
                {
                    v = PictConstants.AggressivelyEscape(string.Format(PictConstants.Culture.NumberFormat, "{0}", vv));
                }
                else
                {
                    v = string.Format(PictConstants.Culture.NumberFormat, "{0}", vv);
                }
                break;

            case PairwiseValueType.ComplexObject:
                if (vv == null)
                {
                    v = PictConstants.NullObjectString;
                }
                else
                {
                    if (!objectLookup.ContainsKey(vv))
                    {
                        // use the hex representation of the count
                        v = string.Format(PictConstants.Culture, "o_{0:X}", objectLookup.Count);
                        objectLookup[vv] = v;
                    }
                    else
                    {
                        v = ((string)objectLookup[vv]);
                    }
                }

                break;

            default:
                throw new NotSupportedException("PairwiseValueType = " + valuex.PairwiseValueType);
            }
            if (settings.ContainsSpecialCharacters(v))
            {
                throw new PairwiseException("Invalid characters in name: " + v);
            }

            if (valuex.IsNegative)
            {
                v = settings.NegativePrefix + v;
            }

            if (includeWeight && weight != PictConstants.DefaultWeight)
            {
                v = v + "(" + weight + ")";
            }

            return(v);
        }
예제 #30
0
 string LookupOutputValueWithoutWeight(PairwiseValue valuex)
 {
     return(LookupWork(valuex, false, valuex.Weight));
 }