當前位置: 首頁>>代碼示例>>C#>>正文


C# SpreadsheetUtilities.Formula類代碼示例

本文整理匯總了C#中SpreadsheetUtilities.Formula的典型用法代碼示例。如果您正苦於以下問題:C# Formula類的具體用法?C# Formula怎麽用?C# Formula使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Formula類屬於SpreadsheetUtilities命名空間,在下文中一共展示了Formula類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: TestMethod1

        public void TestMethod1()
        {
            //stractSpreadsheet sp = new Spreadsheet();

            Formula f = new Formula("2+2");
            
        }
開發者ID:jimibue,項目名稱:cs3505,代碼行數:7,代碼來源:UnitTest1.cs

示例2: TestEqualsWithNormalizer

 public void TestEqualsWithNormalizer()
 {
     Formula a = new Formula("x1 + x2", VarToUpper, IsValid);
     Formula b = new Formula("X1 + X2");
     Assert.AreEqual(true, a.Equals(b));
     Assert.AreEqual(true, b.Equals(a));
 }
開發者ID:Buck417,項目名稱:Second-Half-CS-3500,代碼行數:7,代碼來源:FormulaUnitTest1.cs

示例3: TestEqualsBothNull

 public void TestEqualsBothNull()
 {
     Formula a = new Formula(null);
     Formula b = new Formula(null);
     Assert.AreEqual(true, a == b);
     Assert.AreEqual(true, b == a);
 }
開發者ID:Buck417,項目名稱:Second-Half-CS-3500,代碼行數:7,代碼來源:FormulaUnitTest1.cs

示例4: TestNotEqualsBothNull

 public void TestNotEqualsBothNull()
 {
     Formula a = new Formula(null);
     Formula b = new Formula(null);
     Assert.AreEqual(false, a != b);
     Assert.AreEqual(false, b != a);
 }
開發者ID:Buck417,項目名稱:Second-Half-CS-3500,代碼行數:7,代碼來源:FormulaUnitTest1.cs

示例5: TestEqualsFromToString

 public void TestEqualsFromToString()
 {
     string expression = "x + 2";
     Formula a = new Formula(expression);
     Formula b = new Formula(a.ToString());
     Assert.AreEqual(true, a.Equals(b));
     Assert.AreEqual(true, b.Equals(a));
 }
開發者ID:Buck417,項目名稱:Second-Half-CS-3500,代碼行數:8,代碼來源:FormulaUnitTest1.cs

示例6: SetContentsWithFormulaReturnString

        public string SetContentsWithFormulaReturnString(AbstractSpreadsheet sheet, string name, Formula formula)
        {
            List<string> cell_names = new List<string>(sheet.SetCellContents(name, formula));
            string[] cell_array = cell_names.ToArray();
            string text = string.Join(",", cell_array);

            return text;
        }
開發者ID:Leyalic,項目名稱:PS6_2015,代碼行數:8,代碼來源:SpreadsheetTests.cs

示例7: TestHashCodeTrue

 public void TestHashCodeTrue()
 {
     Formula a = new Formula("2 + X3");
     int hashCodeA = a.GetHashCode();
     Formula b = new Formula("2+X3");
     int hashCodeB = b.GetHashCode();
     Assert.AreEqual(hashCodeA, hashCodeB);
 }
開發者ID:Buck417,項目名稱:Second-Half-CS-3500,代碼行數:8,代碼來源:FormulaUnitTest1.cs

示例8: Main

        static void Main(string[] args)
        {
            String lpPattern = @"\(";
            String rpPattern = @"\)";
            String opPattern = @"[\+\-*/]";
            String varPattern = @"[a-zA-Z_](?: [a-zA-Z_]|\d)*";
            //String doublePattern = @"(?: \d+\.\d* | \d*\.\d+ | \d+ ) (?: [eE][\+-]?\d+)?";
            String doublePattern = @"^[0-9\.]*$";
            String spacePattern = @"\s+";

            // Overall pattern
            String pattern = String.Format("({0}) | ({1}) | ({2}) | ({3}) | ({4}) | ({5})",
                                            lpPattern, rpPattern, opPattern, varPattern, doublePattern, spacePattern);

            Formula f = new Formula("2.0 + x7 + b6+9- c");
               String s = f.GetVariables().ToList().ToString();
            Debug.WriteLine(s);
        }
開發者ID:rachelbrough,項目名稱:3500,代碼行數:18,代碼來源:Program.cs

示例9: Cell

 /// <summary>
 /// Creates a cell that has a formula.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="formula"></param>
 public Cell(String name, Formula formula)
 {
     this.name = name;
     this.formula = formula;
     this.isFormula = true;
 }
開發者ID:jfairbourn,項目名稱:Spreadsheet,代碼行數:11,代碼來源:Cell.cs

示例10: SetContentsOfCell

        /// <summary>
        /// If content is null, throws an ArgumentNullException.
        /// 
        /// Otherwise, if name is null or invalid, throws an InvalidNameException.
        /// 
        /// Otherwise, if content parses as a double, the contents of the named
        /// cell becomes that double.
        /// 
        /// Otherwise, if content begins with the character '=', an attempt is made
        /// to parse the remainder of content into a Formula f using the Formula
        /// constructor.  There are then three possibilities:
        /// 
        ///   (1) If the remainder of content cannot be parsed into a Formula, a 
        ///       SpreadsheetUtilities.FormulaFormatException is thrown.
        ///       
        ///   (2) Otherwise, if changing the contents of the named cell to be f
        ///       would cause a circular dependency, a CircularException is thrown.
        ///       
        ///   (3) Otherwise, the contents of the named cell becomes f.
        /// 
        /// Otherwise, the contents of the named cell becomes content.
        /// 
        /// If an exception is not thrown, the method returns a set consisting of
        /// name plus the names of all other cells whose value depends, directly
        /// or indirectly, on the named cell.
        /// 
        /// For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
        /// set {A1, B1, C1} is returned.
        /// </summary>
        public override ISet<string> SetContentsOfCell(string cell_name, string content)
        {
            has_changed = true;
            string name = Normalize(cell_name);
            double number;
            if (content == null)
            {
                throw new ArgumentNullException();
            }
            else if (name == null || IsValid(name) == false)
            {
                throw new InvalidNameException();
            }
            else if (double.TryParse(content, out number))
            {
                return SetCellContents(name, number);
            }
            else if (content.StartsWith("=") && content.Length>1)
            {
                Formula formula;
                try
                {
                    string sub_content = content.Substring(1);
                    formula = new Formula(normalize_function(sub_content, Normalize));
                }
                catch
                {

                    throw new FormulaFormatException("Invalid Formula");
                }
                try
                {
                    return SetCellContents(name, formula);
                }
                catch (Exception)
                {

                    throw new CircularException();
                }
            }
            else if (content.StartsWith("=") && content.Length <= 1)
            {
                throw new FormulaFormatException("Invalid Fomula");
            }
            else
            {
                return SetCellContents(name, content);
            }
        }
開發者ID:RyanJones0814,項目名稱:spreadsheet,代碼行數:78,代碼來源:Spreadsheet.cs

示例11: SetCellContents

        /// <summary>
        /// An implementation of the abstract method in AbstractSpreadsheet.
        /// <seealso cref="AbstractSpreadsheet.SetCellContents(String, Formula)"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="formula"></param>
        /// <returns></returns>
        protected override ISet<String> SetCellContents(String name, Formula formula)
        {
            // If formula parameter is null, throws an ArgumentNullException.
            // Otherwise, if name is null or invalid, throws an InvalidNameException.
            name = CorrectInput(name, formula);
            formula = NormalizeFormula(formula);

            // Otherwise, if changing the contents of the named cell to be the formula would cause a
            // circular dependency, throws a CircularException.
            IEnumerable<string> previous = dependencies.GetDependees(name);
            try
            {
                dependencies.ReplaceDependees(name, formula.GetVariables());
                GetCellsToRecalculate(name);
            }
            catch (CircularException)
            {
                dependencies.ReplaceDependees(name, previous);
                throw new CircularException();
            };

            //foreach (string v in formula.GetVariables())
            //    foreach (string d in GetCellsToRecalculate(v))
            //        if (name.Equals(d))
            //        {
            //            dependencies.ReplaceDependees(name, previous);
            //            throw new CircularException();
            //        }

            // Otherwise, the contents of the named cell becomes formula.
            Changed = true;
            GetCell(name).Contents = formula;

            // The method returns a Set consisting of name plus the names of all other
            // cells whose value depends, directly or indirectly, on the named cell.
            return new HashSet<string>(GetCellsToRecalculate(name));
        }
開發者ID:jam98,項目名稱:Spreadsheet,代碼行數:44,代碼來源:Spreadsheet.cs

示例12: SetContentsOfCell

        /// <summary>
        /// An implementation of the abstract method in AbstractSpreadsheet.
        /// <seealso cref="AbstractSpreadsheet.SetContentsOfCell"/>
        /// </summary>
        /// <param name="name"></param>
        /// <param name="content"></param>
        /// <returns></returns>
        public override ISet<string> SetContentsOfCell(string name, string content)
        {
            // Private Variable
            ISet<string> set;

            // If content is null, throws an ArgumentNullException.
            // Otherwise, if name is null or invalid, throws an InvalidNameException.
            name = CorrectInput(name, content);

            // Otherwise, if content parses as a double, the contents of the named
            // cell becomes that double.
            double d;
            if (Double.TryParse(content, out d))
                set = SetCellContents(name, d);

            // Otherwise, if content begins with the character '=', an attempt is made
            // to parse the remainder of content into a Formula f using the Formula
            // constructor.
            else if (content.Length > 0 && content[0] == '=')
            {
                // There are then three possibilities:
                //   (1) If the remainder of content cannot be parsed into a Formula, a
                //       SpreadsheetUtilities.FormulaFormatException is thrown.
                //       Be sure to check the validity of and normalize any variables.
                //   (2) Otherwise, if changing the contents of the named cell to be f
                //       would cause a circular dependency, a CircularException is thrown.
                Formula f = new Formula(content.Substring(1));
                f = NormalizeFormula(f);
                try
                {
                    foreach (string v in f.GetVariables())
                        CorrectInput(v);
                }
                catch (InvalidNameException)
                {
                    throw new FormulaFormatException(
                        String.Format("One or more variables in the formula '{0}' contained in cell {1} aren't valid.", f.ToString(), name));
                }

                //   (3) Otherwise, the contents of the named cell becomes f.
                set = SetCellContents(name, f);
            }

            // Otherwise, the contents of the named cell becomes content.
            else
                set = SetCellContents(name, content);

            // Recalculate the values of any cell dependent on the named cell, including the named cell itself.
            CalculateCellValues(name);

            //Remove any name associations to cell, reset to how it was before the cell was added.
            if (content == "")
            {
                cells.Remove(name);
            }

            // If an exception is not thrown, the method returns a set consisting of
            // name plus the names of all other cells whose value depends, directly
            // or indirectly, on the named cell.
            // For example, if name is A1, B1 contains A1*2, and C1 contains B1+A1, the
            // set {A1, B1, C1} is returned.
            return set;
        }
開發者ID:jam98,項目名稱:Spreadsheet,代碼行數:70,代碼來源:Spreadsheet.cs

示例13: TestEquals8

 public void TestEquals8()
 {
     Formula f = new Formula("x7 + 7");
     Assert.IsFalse(f == new Formula("2.000 + x7"));
 }
開發者ID:HeroOfCanton,項目名稱:CS3500,代碼行數:5,代碼來源:FormulaTester.cs

示例14: TestEquals6

 public void TestEquals6()
 {
     Formula f = new Formula("x7 + 7");
     Assert.IsFalse(f != new Formula("x7 + 7"));
 }
開發者ID:HeroOfCanton,項目名稱:CS3500,代碼行數:5,代碼來源:FormulaTester.cs

示例15: Test28

 public void Test28()
 {
     Formula f = new Formula("a4-a4*a4/a4");
     Assert.AreEqual(0.0, f.Evaluate(s => 3));
 }
開發者ID:HeroOfCanton,項目名稱:CS3500,代碼行數:5,代碼來源:FormulaTester.cs


注:本文中的SpreadsheetUtilities.Formula類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。