Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.GP.Tests/Token.cs @ 2479

Last change on this file since 2479 was 2447, checked in by gkronber, 15 years ago

Added until test project for HeuristicLab.GP plugins. #791 (Tests for GP operators and structure identification evaluators)

File size: 2.3 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2008 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Text;
26using System.IO;
27using HeuristicLab.GP;
28using HeuristicLab.GP.Interfaces;
29using HeuristicLab.GP.StructureIdentification;
30using System.Diagnostics;
31
32namespace HeuristicLab.GP.Test {
33  public enum TokenSymbol { LPAR, RPAR, SYMB, NUMBER };
34  public class Token {
35    public static readonly Token LPAR = Token.Parse("(");
36    public static readonly Token RPAR = Token.Parse(")");
37
38    public TokenSymbol Symbol { get; set; }
39    public string StringValue { get; set; }
40    public double DoubleValue { get; set; }
41    public Token() { }
42
43    public override bool Equals(object obj) {
44      Token other = (obj as Token);
45      if (other == null) return false;
46      if (other.Symbol != Symbol) return false;
47      return other.StringValue == this.StringValue;
48    }
49
50    public static Token Parse(string strToken) {
51      strToken = strToken.Trim();
52      Token t = new Token();
53      t.StringValue = strToken.Trim();
54      double temp;
55      if (strToken == "") {
56        t = null;
57      } else if (strToken == "(") {
58        t.Symbol = TokenSymbol.LPAR;
59      } else if (strToken == ")") {
60        t.Symbol = TokenSymbol.RPAR;
61      } else if (double.TryParse(strToken, out temp)) {
62        t.Symbol = TokenSymbol.NUMBER;
63        t.DoubleValue = double.Parse(strToken);
64      } else {
65        t.Symbol = TokenSymbol.SYMB;
66      }
67      return t;
68    }
69  }
70}
Note: See TracBrowser for help on using the repository browser.