示例#1
0
        private ESection ProcessCluster(int lineNumber, string currentLine, ESection currentSection, ref EClusterState currentClusterState)
        {
            if (currentLine.StartsWith(
                    TestFileStrings.EndCluster, StringComparison.OrdinalIgnoreCase))
            {
                if (EClusterState.Variable != currentClusterState)
                {
                    Validate.Fail(string.Format("Unexpected END CLUSTER line {0}: {1}", lineNumber, currentLine));
                }
                currentSection = ESection.PreClusterOrConstraints;
                this.ClusterDefs.Add(this.currentClusterDef);
                this.currentClusterDef = null;
                return(currentSection);
            }
            if (EClusterState.Id == currentClusterState)
            {
                Match m = TestFileStrings.ParseClusterId.Match(currentLine);
                if (m.Success)
                {
                    // Verify the Clusters in the file are sorted on ID.  This makes it easier for the results
                    // reading to be in sync, as we'll index ClusterDefs by [Parent - 1].
                    var id = int.Parse(m.Groups["id"].ToString());
                    Validate.IsTrue(this.currentClusterDef.ClusterId == id, "Out of order CLUSTER id");
                }
                else
                {
                    Validate.Fail(string.Format("Unparsable CLUSTER ID line {0}: {1}", lineNumber, currentLine));
                }
                currentClusterState = EClusterState.Parent;
            }
            else if (EClusterState.Parent == currentClusterState)
            {
                Match m = TestFileStrings.ParseClusterParent.Match(currentLine);
                if (m.Success)
                {
                    int parentId = int.Parse(m.Groups["parent"].ToString());

                    // Cluster IDs are 1-based because we use 0 for the "root cluster".
                    if (0 != parentId)
                    {
                        ClusterDef clusParent = this.ClusterDefs[parentId - 1];
                        Validate.AreEqual(clusParent.ClusterId, parentId, "clusParent.ClusterId mismatch with idParent");
                        clusParent.AddClusterDef(this.currentClusterDef);
                    }
                }
                else
                {
                    Validate.Fail(string.Format("Unparsable CLUSTER Parent line {0}: {1}", lineNumber, currentLine));
                }
                currentClusterState = EClusterState.LeftBorder;
            }
            else if (EClusterState.LeftBorder == currentClusterState)
            {
                // Older files didn't have MinSize.
                Match m = TestFileStrings.ParseClusterMinSize.Match(currentLine);
                if (m.Success)
                {
                    this.currentClusterDef.MinimumSizeX = double.Parse(m.Groups["X"].ToString());
                    this.currentClusterDef.MinimumSizeY = double.Parse(m.Groups["Y"].ToString());
                    return(currentSection);
                }
                if (0 == string.Compare("NewHierarchy", currentLine, StringComparison.OrdinalIgnoreCase))
                {
                    // NewHierarchy is optional.
                    this.currentClusterDef.IsNewHierarchy = true;
                    return(currentSection);
                }
                this.currentClusterDef.LeftBorderInfo = ParseBorderInfo("Left", currentLine, lineNumber);
                currentClusterState = EClusterState.RightBorder;
            }
            else if (EClusterState.RightBorder == currentClusterState)
            {
                this.currentClusterDef.RightBorderInfo = ParseBorderInfo("Right", currentLine, lineNumber);
                currentClusterState = EClusterState.TopBorder;
            }
            else if (EClusterState.TopBorder == currentClusterState)
            {
                this.currentClusterDef.TopBorderInfo = ParseBorderInfo("Top", currentLine, lineNumber);
                currentClusterState = EClusterState.BottomBorder;
            }
            else if (EClusterState.BottomBorder == currentClusterState)
            {
                this.currentClusterDef.BottomBorderInfo = ParseBorderInfo("Bottom", currentLine, lineNumber);
                currentClusterState = EClusterState.Variable;
            }
            else if (EClusterState.Variable == currentClusterState)
            {
                Match m = TestFileStrings.ParseClusterVariable.Match(currentLine);
                if (m.Success)
                {
                    int variableId = int.Parse(m.Groups["var"].ToString());
                    this.currentClusterDef.AddVariableDef(this.VariableDefs[variableId]);
                }
                else
                {
                    Validate.Fail(string.Format("Unparsable CLUSTER Variable line {0}: {1}", lineNumber, currentLine));
                }
            }
            return(currentSection);
        }
示例#2
0
 private ESection ProcessClusterOrConstraints(string currentLine, ESection currentSection, ref EClusterState currentClusterState)
 {
     if (currentLine.StartsWith(
             TestFileStrings.BeginCluster, StringComparison.OrdinalIgnoreCase))
     {
         currentSection         = ESection.Cluster;
         currentClusterState    = EClusterState.Id;
         this.currentClusterDef = new ClusterDef(this.MinClusterSizeX, this.MinClusterSizeY);
         return(currentSection);
     }
     if (currentLine.StartsWith(
             TestFileStrings.BeginConstraintsX, StringComparison.OrdinalIgnoreCase))
     {
         currentSection             = ESection.Constraints;
         this.currentConstraintDefs = this.ConstraintDefsX;
         return(currentSection);
     }
     if (currentLine.StartsWith(
             TestFileStrings.BeginConstraintsY, StringComparison.OrdinalIgnoreCase))
     {
         currentSection             = ESection.Constraints;
         this.currentConstraintDefs = this.ConstraintsDefY;
         return(currentSection);
     }
     if (currentLine.StartsWith(
             TestFileStrings.BeginConstraints, StringComparison.OrdinalIgnoreCase))
     {
         currentSection             = ESection.Constraints;
         this.currentConstraintDefs = this.ConstraintDefsX;
         return(currentSection);
     }
     return(currentSection);
 }
        private ESection ProcessCluster(int lineNumber, string currentLine, ESection currentSection, ref EClusterState currentClusterState)
        {
            if (currentLine.StartsWith(
                TestFileStrings.EndCluster, StringComparison.OrdinalIgnoreCase))
            {
                if (EClusterState.Variable != currentClusterState)
                {
                    Validate.Fail(string.Format("Unexpected END CLUSTER line {0}: {1}", lineNumber, currentLine));
                }
                currentSection = ESection.PreClusterOrConstraints;
                this.ClusterDefs.Add(this.currentClusterDef);
                this.currentClusterDef = null;
                return currentSection;
            }
            if (EClusterState.Id == currentClusterState)
            {
                Match m = TestFileStrings.ParseClusterId.Match(currentLine);
                if (m.Success)
                {
                    // Verify the Clusters in the file are sorted on ID.  This makes it easier for the results
                    // reading to be in sync, as we'll index ClusterDefs by [Parent - 1].
                    var id = int.Parse(m.Groups["id"].ToString());
                    Validate.IsTrue(this.currentClusterDef.ClusterId == id, "Out of order CLUSTER id");
                }
                else
                {
                    Validate.Fail(string.Format("Unparsable CLUSTER ID line {0}: {1}", lineNumber, currentLine));
                }
                currentClusterState = EClusterState.Parent;
            }
            else if (EClusterState.Parent == currentClusterState)
            {
                Match m = TestFileStrings.ParseClusterParent.Match(currentLine);
                if (m.Success)
                {
                    int parentId = int.Parse(m.Groups["parent"].ToString());

                    // Cluster IDs are 1-based because we use 0 for the "root cluster".
                    if (0 != parentId)
                    {
                        ClusterDef clusParent = this.ClusterDefs[parentId - 1];
                        Validate.AreEqual(clusParent.ClusterId, parentId, "clusParent.ClusterId mismatch with idParent");
                        clusParent.AddClusterDef(this.currentClusterDef);
                    }
                }
                else
                {
                    Validate.Fail(string.Format("Unparsable CLUSTER Parent line {0}: {1}", lineNumber, currentLine));
                }
                currentClusterState = EClusterState.LeftBorder;
            }
            else if (EClusterState.LeftBorder == currentClusterState)
            {
                // Older files didn't have MinSize.
                Match m = TestFileStrings.ParseClusterMinSize.Match(currentLine);
                if (m.Success)
                {
                    this.currentClusterDef.MinimumSizeX = double.Parse(m.Groups["X"].ToString());
                    this.currentClusterDef.MinimumSizeY = double.Parse(m.Groups["Y"].ToString());
                    return currentSection;
                }
                if (0 == string.Compare("NewHierarchy", currentLine, StringComparison.OrdinalIgnoreCase))
                {
                    // NewHierarchy is optional.
                    this.currentClusterDef.IsNewHierarchy = true;
                    return currentSection;
                }
                this.currentClusterDef.LeftBorderInfo = ParseBorderInfo("Left", currentLine, lineNumber);
                currentClusterState = EClusterState.RightBorder;
            }
            else if (EClusterState.RightBorder == currentClusterState)
            {
                this.currentClusterDef.RightBorderInfo = ParseBorderInfo("Right", currentLine, lineNumber);
                currentClusterState = EClusterState.TopBorder;
            }
            else if (EClusterState.TopBorder == currentClusterState)
            {
                this.currentClusterDef.TopBorderInfo = ParseBorderInfo("Top", currentLine, lineNumber);
                currentClusterState = EClusterState.BottomBorder;
            }
            else if (EClusterState.BottomBorder == currentClusterState)
            {
                this.currentClusterDef.BottomBorderInfo = ParseBorderInfo("Bottom", currentLine, lineNumber);
                currentClusterState = EClusterState.Variable;
            }
            else if (EClusterState.Variable == currentClusterState)
            {
                Match m = TestFileStrings.ParseClusterVariable.Match(currentLine);
                if (m.Success)
                {
                    int variableId = int.Parse(m.Groups["var"].ToString());
                    this.currentClusterDef.AddVariableDef(this.VariableDefs[variableId]);
                }
                else
                {
                    Validate.Fail(string.Format("Unparsable CLUSTER Variable line {0}: {1}", lineNumber, currentLine));
                }
            }
            return currentSection;
        }
示例#4
0
        // Some variables are instantiated after we see the section header.
        // ReSharper disable PossibleNullReferenceException
        public void Load(string strFullName)
        {
            this.VariableDefs.Clear();
            this.ConstraintDefsX.Clear();
            this.ConstraintsDefY.Clear();

            using (var sr = new StreamReader(strFullName))
            {
                string        currentLine;
                ESection      currentSection      = ESection.PreVariables;
                EClusterState currentClusterState = EClusterState.Id;
                int           lineNumber          = 0;
                while ((currentLine = sr.ReadLine()) != null)
                {
                    ++lineNumber;
                    if (string.IsNullOrEmpty(currentLine) || currentLine.StartsWith("//", StringComparison.OrdinalIgnoreCase))
                    {
                        continue;
                    }

                    if (ESection.Done == currentSection)
                    {
                        break;
                    }

                    switch (currentSection)
                    {
                    case ESection.PreVariables:
                        // Some stuff gets in at the top before variables.
                        currentSection = ProcessPreVariables(lineNumber, currentLine, currentSection);
                        break;

                    case ESection.Variables:
                        currentSection = ProcessVariables(lineNumber, currentLine, currentSection);
                        break;

                    case ESection.PreClusterOrConstraints:
                        currentSection = ProcessClusterOrConstraints(currentLine, currentSection, ref currentClusterState);
                        break;

                    case ESection.Cluster:
                        currentSection = ProcessCluster(lineNumber, currentLine, currentSection, ref currentClusterState);
                        break;

                    case ESection.Constraints:
                        currentSection = ProcessConstraints(lineNumber, currentLine, currentSection);
                        break;

                    case ESection.PreNeighboursOrResults:
                        currentSection = ProcessNeighboursOrResults(currentLine, currentSection);
                        break;

                    case ESection.Neighbours:
                        currentSection = ProcessNeighbours(lineNumber, currentLine, currentSection);
                        break;

                    case ESection.PreResults:
                        currentSection = ProcessPreResults(currentLine, currentSection);
                        break;

                    case ESection.Results:
                        currentSection = ProcessResults(lineNumber, currentLine, currentSection);
                        break;

                    case ESection.PreClusterResults:
                        currentSection = ProcessPreClusterResults(currentLine, currentSection);
                        break;

                    case ESection.ClusterResults:
                        currentSection = ProcessClusterResults(lineNumber, currentLine, currentSection);
                        break;

                    default:
                        Validate.Fail("Unknown section");
                        break;
                    }
                } // endwhile sr.ReadLine
            }     // end using sr

            if (0 == this.VariableDefs.Count)
            {
                Validate.Fail("No VARIABLEs found in file");
            }
        }
 private ESection ProcessClusterOrConstraints(string currentLine, ESection currentSection, ref EClusterState currentClusterState)
 {
     if (currentLine.StartsWith(
         TestFileStrings.BeginCluster, StringComparison.OrdinalIgnoreCase))
     {
         currentSection = ESection.Cluster;
         currentClusterState = EClusterState.Id;
         this.currentClusterDef = new ClusterDef(this.MinClusterSizeX, this.MinClusterSizeY);
         return currentSection;
     }
     if (currentLine.StartsWith(
         TestFileStrings.BeginConstraintsX, StringComparison.OrdinalIgnoreCase))
     {
         currentSection = ESection.Constraints;
         this.currentConstraintDefs = this.ConstraintDefsX;
         return currentSection;
     }
     if (currentLine.StartsWith(
         TestFileStrings.BeginConstraintsY, StringComparison.OrdinalIgnoreCase))
     {
         currentSection = ESection.Constraints;
         this.currentConstraintDefs = this.ConstraintsDefY;
         return currentSection;
     }
     if (currentLine.StartsWith(
         TestFileStrings.BeginConstraints, StringComparison.OrdinalIgnoreCase))
     {
         currentSection = ESection.Constraints;
         this.currentConstraintDefs = this.ConstraintDefsX;
         return currentSection;
     }
     return currentSection;
 }