Skip to content
Browse files

-add: new UnitTest to test comparison between IToken and MutexTokenImpl

-bugfix: comparsion between ANTLR.IToken and MutexTokenImpl now working correctly (now using TokenWrapper.tokenHashCode - which is correctly initialized in the constructor)
-bugfix: Striping of templates now works in GSTConsole project (missing
  • Loading branch information...
1 parent f4a5c07 commit 22e4320bb687e5b2ba454c01134989634c6599b6 @yas4891 committed
View
16 CTokenizer/LexerHelper.cs
@@ -206,23 +206,7 @@ public static IEnumerable<IToken> GetTokens(this Lexer lexer)
lexer.Reset();
return list;
}
-
- /*
- public static IEnumerable<string> GetDebugTokenStrings(this Lexer lexer, TokenFactory factory)
- {
- var lexerType = lexer.GetType();
-
- return lexer.GetTokens().Select(
- token => string.Format("[{0:000}:{1:00}] {2}\t\t- {3}",
- token.Line,
- token.CharPositionInLine,
- factory.GetTokenName(token.Type, lexerType),
- token.Text))
- .ToList();
- }
- /* */
-
/// <summary>
/// returns a bunch of debug information for the tokens
/// </summary>
View
33 GSTAppLogic/test/model/ComparisonModelTest.cs
@@ -3,6 +3,12 @@
using DataRepository;
using GSTAppLogic.app.model;
using NUnit.Framework;
+using Antlr.Runtime;
+using System;
+using GSTLibrary.token;
+using Tokenizer;
+using GSTLibrary.tile;
+using GSTAppLogic.ext;
namespace GSTAppLogic.test.model
{
@@ -30,5 +36,32 @@ public void Default()
Assert.AreEqual(100, model.MaximumSimilarity);
}
+
+ [Test]
+ public void ANTLRITokenVersusMutexTokenImpl()
+ {
+ var factory = new MutexTokenFactory();
+ var itokens = factory.GetTokenWrapperListFromSource("void main(int argc, char** argv)").ToGSTTokenList();
+
+ var tokennames = new[] { "VOID", "IDENTIFIER", "INTEGER_DATATYPE", "IDENTIFIER", "POINTER_DATATYPE", "IDENTIFIER" };
+ var mutextokens = factory.GetTokenWrapperEnumerable(tokennames).ToGSTTokenList();
+
+ for (int i = 0; i < itokens.Count; i++)
+ {
+ Assert.AreEqual(itokens[i].GetHashCode(), mutextokens[i].GetHashCode());
+ }
+
+ var algo = new HashingGSTAlgorithm<GSTToken<TokenWrapper>>(itokens, mutextokens)
+ {
+ MinimumMatchLength = 3
+ };
+
+ algo.RunToCompletion();
+
+
+ Assert.AreEqual(100, algo.Similarity);
+
+
+ }
}
}
View
9 GSTConsole/Program.cs
@@ -31,6 +31,7 @@ static void Main(string[] args)
cLogger.DebugFormat("64-bit process: {0}", Environment.Is64BitProcess);
Console.WriteLine();
+ /*
IEnumerable<string> defaultTokenSet = new[]
{
"INCREMENT", "ADDEQUAL", "ARRAY_ACCESS",
@@ -44,8 +45,8 @@ static void Main(string[] args)
}, factory);
model.Calculate();
-
- /*
+ /* */
+
string student;
string assignment;
string path;
@@ -90,7 +91,7 @@ static void Main(string[] args)
cLogger.DebugFormat("total runtime: {0} ms", watch.ElapsedMilliseconds);
Console.WriteLine("{0}", appLogic.MaximumSimilarity);
Console.WriteLine("{0}", appLogic.MaxSimilarityStudentIdentifier);
-
+
#if DEBUG
if (Environment.UserInteractive)
Console.ReadLine();
@@ -117,7 +118,7 @@ private static string GetSource(string path, string templatePath)
{
return (string.IsNullOrWhiteSpace(templatePath))
? File.ReadAllText(path)
- : TemplatingHelper.StripTemplateFromSourceFile(path, templatePath);
+ : File.ReadAllText(TemplatingHelper.StripTemplateFromSourceFile(path, templatePath));
}
/// <summary>
View
121 GSTConsole/bin/Debug/main-01.c
@@ -0,0 +1,121 @@
+#define _ CRT_SECURE_NO_WARNINGS
+#include <stdio.h>
+#include <string.h>
+void _stdcall Sleep(long ms);
+
+
+void Ticker(char *s, int len);
+
+void main (void){
+ int i = 1;
+ int j = 0;
+ char name[80] = "";
+ char s1[4] = "Max";
+ char s2[1] = "";
+
+ while(i = 1)
+ {
+ printf("Bitte einen Namen eingeben: \n");
+ fflush(stdin);
+ scanf("%79[^\n]s", name);
+ if (strlen(name)== 0)
+ printf("Fehler\n\n");
+ else
+ {
+ for (j=strlen(name);j<=78;j++)
+ {
+ strcat(name," ");
+ }
+
+
+ //Ticker(s1, strlen(s1));
+ //Ticker(s2, strlen(s2));
+
+
+ for(j=0; j <= 100; j++)
+ {
+ Ticker(name, strlen(name));
+
+ printf("%4s\r",name);
+ Sleep(50);
+
+ }
+
+ }
+ /*printf("s1 ist > %4s < \n" , s1);
+ printf("s2 ist > %4s < \n" , s2);*/
+
+
+
+
+
+ }
+}
+
+
+void Ticker(char *s, int len){
+
+ int j = 0;
+ int counter = 0;
+ if (len > 1)
+ {
+
+
+
+ int i = 0;
+ char t;
+
+ for(i;i<=77;i++)
+ {
+ t = s[i];
+ s[i] = s[i+1];
+ s[i+1] = t;
+ }
+
+
+ }
+ else return;
+
+}
+
+
+
+
+
+
+
+
+
+
+ //char sp1;
+ //char sp2;
+ //char sp3;
+
+
+ // sp1 = s[len-1] ; /*Platz 3 wird gespeichert = x*/
+ // sp2 = s[len-2] ; /*Platz 2 wird gespeichert = a*/
+ // sp3 = s[len-3] ; /*Platz 1 wird gespeichert = m*/
+
+
+
+
+
+ // s[0] = sp2;
+ // s[1] = sp1;
+ // s[2] = sp3;
+ //
+ //
+ //char sp0 = s[0];
+ //char sp1 = s[1];
+ //char sp2 = s[2];
+ //char sp3 = s[3];
+ //char sp4 = s[4];
+ //char sp5 = s[5];
+ //char sp6 = s[6];
+ //char sp7 = s[7];
+ //char sp8 = s[8];
+ //char sp9 = s[9];
+ //char sp10 = s[10];
+ //char sp11 = s[11];
+ //char sp12 = s[12];
+ //
View
3 GSTLibrary/GSTLibrary.csproj
@@ -31,6 +31,9 @@
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
+ <Reference Include="log4net">
+ <HintPath>..\ThirdPartyLibs\log4net.dll</HintPath>
+ </Reference>
<Reference Include="nunit.framework, Version=2.5.8.10295, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\nunit.framework.dll</HintPath>
View
9 GSTLibrary/tile/HashingGSTAlgorithm.cs
@@ -6,6 +6,7 @@
using GSTLibrary.exception;
using GSTLibrary.token;
using System.Threading;
+using log4net;
namespace GSTLibrary.tile
{
@@ -24,6 +25,7 @@ namespace GSTLibrary.tile
/// <typeparam name="T"></typeparam>
public class HashingGSTAlgorithm<T> : AbstractGSTAlgorithm<T> where T : GSTToken
{
+ private static readonly ILog cLogger = LogManager.GetLogger(typeof(HashingGSTAlgorithm<T>).Name);
/// <summary>
/// handles the hashing of any number of tokens and stores the hash values.
/// Used to abstract the implementation out of the algorithm
@@ -151,6 +153,13 @@ public override void DoOneRun()
if(!initialized)
{
InitializeHashes();
+
+ /*
+ for (int i = 0; i < ListA.Count; i++)
+ {
+ cLogger.DebugFormat("A: {0}, B:{1}", ListA[i].GetHashCode(), ListB[i].GetHashCode());
+ }
+ /* */
}
MatchesList = new List<Tile<T>>();
View
27 GSTTests.VisualState.xml
@@ -1,25 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<VisualState xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" ShowCheckBoxes="true">
- <TopNode>[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit</TopNode>
- <SelectedNode>[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit</SelectedNode>
+ <TopNode>[0-1035]GSTLibrary</TopNode>
+ <SelectedNode>[0-1006]GSTLibrary.test.tile.HashingGSTAlgorithmTest</SelectedNode>
<ExcludeCategories>false</ExcludeCategories>
<Nodes>
- <Node UniqueName="[0-1000]D:\wissen\csharp\GreedyStringTiling\GSTTests.nunit" Expanded="true" />
- <Node UniqueName="[0-1034]D:\wissen\csharp\GreedyStringTiling\GSTLibrary\bin\Debug\GSTLibrary.dll" Expanded="true" />
+ <Node UniqueName="[0-1000]D:\Wissen\csharp\GreedyStringTiling\GSTTests.nunit" Expanded="true" />
+ <Node UniqueName="[0-1034]D:\Wissen\csharp\GreedyStringTiling\GSTLibrary\bin\Debug\GSTLibrary.dll" Expanded="true" />
<Node UniqueName="[0-1035]GSTLibrary" Expanded="true" />
<Node UniqueName="[0-1036]GSTLibrary.test" Expanded="true" />
<Node UniqueName="[0-1037]GSTLibrary.test.tile" Expanded="true" />
<Node UniqueName="[0-1038]GSTLibrary.test.token" Expanded="true" />
- <Node UniqueName="[0-1041]D:\wissen\csharp\GreedyStringTiling\CTokenizer\bin\Debug\CTokenizer.dll" Expanded="true" />
+ <Node UniqueName="[0-1041]D:\Wissen\csharp\GreedyStringTiling\CTokenizer\bin\Debug\CTokenizer.dll" Expanded="true" />
<Node UniqueName="[0-1042]CTokenizer" Expanded="true" />
<Node UniqueName="[0-1043]CTokenizer.test" Expanded="true" />
- <Node UniqueName="[0-1048]D:\wissen\csharp\GreedyStringTiling\GSTAppLogic\bin\Debug\GSTAppLogic.dll" Expanded="true" />
- <Node UniqueName="[0-1049]GSTAppLogic" Expanded="true" />
- <Node UniqueName="[0-1050]GSTAppLogic.test" Expanded="true" />
- <Node UniqueName="[0-1051]GSTAppLogic.test.model" Expanded="true" />
- <Node UniqueName="[0-1052]GSTAppLogic.test.templating" Expanded="true" />
- <Node UniqueName="[0-1056]D:\wissen\csharp\GreedyStringTiling\GSTConsole\bin\Debug\GSTConsole.exe" Expanded="true" />
- <Node UniqueName="[0-1057]GSTConsole" Expanded="true" />
- <Node UniqueName="[0-1058]GSTConsole.test" Expanded="true" />
+ <Node UniqueName="[0-1049]D:\Wissen\csharp\GreedyStringTiling\GSTAppLogic\bin\Debug\GSTAppLogic.dll" Expanded="true" />
+ <Node UniqueName="[0-1050]GSTAppLogic" Expanded="true" />
+ <Node UniqueName="[0-1051]GSTAppLogic.test" Expanded="true" />
+ <Node UniqueName="[0-1052]GSTAppLogic.test.model" Expanded="true" />
+ <Node UniqueName="[0-1044]GSTAppLogic.test.model.ComparisonModelTest" Expanded="true" />
+ <Node UniqueName="[0-1053]GSTAppLogic.test.templating" Expanded="true" />
+ <Node UniqueName="[0-1057]D:\Wissen\csharp\GreedyStringTiling\GSTConsole\bin\Debug\GSTConsole.exe" Expanded="true" />
+ <Node UniqueName="[0-1058]GSTConsole" Expanded="true" />
+ <Node UniqueName="[0-1059]GSTConsole.test" Expanded="true" />
</Nodes>
</VisualState>
View
1 Tokenizer/TokenType.cs
@@ -24,6 +24,7 @@ public override bool Equals(object obj)
public override int GetHashCode()
{
+ //Console.WriteLine("TokenType: got called for {0}", Type);
return Type.GetHashCode();
}
View
4 Tokenizer/TokenWrapper.cs
@@ -13,7 +13,7 @@ public class TokenWrapper
/// <summary>
/// stores the hash code of the underlying token to speed up comparison
/// </summary>
- private readonly long tokenHashCode;
+ private readonly Int32 tokenHashCode;
/// <summary>
/// the saved token object from ANTLR lexers
@@ -72,7 +72,7 @@ public override bool Equals(object obj)
public override int GetHashCode()
{
- return null == Token ? Type.GetHashCode() : Token.GetHashCode();
+ return tokenHashCode; // null == Token ? Type.GetHashCode() : Token.GetHashCode();
}
public override string ToString()

0 comments on commit 22e4320

Please sign in to comment.
Something went wrong with that request. Please try again.