~a-j-delaney/libamore/cunit-dev

« back to all changes in this revision

Viewing changes to src/libAMoRE/libtest.c

  • Committer: buraq
  • Date: 2004-04-16 17:04:28 UTC
  • Revision ID: vcs-imports@canonical.com-20040416170428-ko6l3kyx1c5jyrll
initial

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *  Copyright (c) ?    - 2000 Lehrstuhl fuer Informatik VII, RWTH Aachen
 
3
 *  Copyright (c) 2000 - 2002 Burak Emir
 
4
 *  This file is part of the libAMoRE library.
 
5
 *
 
6
 *  libAMoRE is  free software; you can redistribute it and/or
 
7
 *  modify it under the terms of the GNU Lesser General Public
 
8
 *  License as published by the Free Software Foundation; either
 
9
 *  version 2.1 of the License, or (at your option) any later version.
 
10
 *  You should have received a copy of the GNU Lesser General Public
 
11
 *  License along with the GNU C Library; if not, write to the Free
 
12
 *  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
 
13
 *  02111-1307 USA.  
 
14
 */
 
15
 
 
16
/* libtest.c
 
17
 */
 
18
 
 
19
#include "libtest.h"
 
20
#include <stdio.h>
 
21
 
 
22
/* #include "obj.h" */
 
23
#include "vars.h"
 
24
 
 
25
#include "rexFromString.h"
 
26
 
 
27
#include "buffer.h"
 
28
 
 
29
#include "string.h"
 
30
#include "nfa2dfa.h"
 
31
#include "rex2nfa.h"
 
32
#include "genrex2nfa.h"
 
33
#include "dfamdfa.h"
 
34
#include "dfa2mon.h"
 
35
 
 
36
 
 
37
#include "debugPrint.h"
 
38
 
 
39
//char *rexstr = "aba*ab";
 
40
char *rexstr = "(aba*)-(abaaa)";
 
41
// test suite 1
 
42
 
 
43
 
 
44
extern PARSE_RESULT errorParseResult;
 
45
 
 
46
regex r1;
 
47
 
 
48
int constr_rexFromString() {
 
49
  printf("\nconstructing RegExp r:");
 
50
  r1 = rexFromString(2, rexstr);
 
51
  printf("result: %s\n",r1->exprex);
 
52
  return 1;
 
53
}
 
54
 
 
55
nfa n1;
 
56
 
 
57
int transf_rex2nfa(regex r) {
 
58
  printf("\n  transforming Rex to Nfa");
 
59
  n1 = rex2nfa(r);  
 
60
  printf("\n  result:");
 
61
  debugPrintNfa( n1 );
 
62
  return 1;
 
63
}
 
64
 
 
65
int transf_genrex2nfa(regex r) {
 
66
  printf("\n  transforming GenRex to Nfa");
 
67
  n1 = genrex2nfa(r);  
 
68
  printf("\n  result:");
 
69
  debugPrintNfa( n1 );
 
70
  return 1;
 
71
}
 
72
 
 
73
dfa d1;
 
74
 
 
75
int transf_nfa2dfa() {
 
76
  printf("\n  transforming to Dfa");
 
77
  d1 = nfa2dfa(n1);
 
78
  printf("\n  result:");
 
79
  debugPrintDfa( d1 );
 
80
  return 1;
 
81
}
 
82
 
 
83
void transf_dfa2mindfa() {
 
84
  printf("\n   minimizing dfa");
 
85
  d1 = dfamdfa( d1, TRUE );
 
86
  printf("\n  result:");
 
87
  debugPrintDfa( d1 );
 
88
}
 
89
 
 
90
monoid m;
 
91
 
 
92
void transf_dfa2mon() {
 
93
  printf("\n  transforming dfa to monoid:");
 
94
 
 
95
  m = dfa2mon( d1 );
 
96
  printf("\n  done.\n");
 
97
}
 
98
// cloning
 
99
 
 
100
int clone_dfa(dfa d) {
 
101
  dfa p;
 
102
  printf("Testing clonedfa...\n");
 
103
  p = clonedfa( d );
 
104
  printf("result:\n");
 
105
  debugPrintDfa( p ); 
 
106
  return 1;
 
107
}
 
108
 
 
109
int clone_nfa(nfa n) {
 
110
    nfa p;
 
111
    printf("Testing clonenfa...\n");
 
112
    p = clonenfa( n1 );
 
113
    printf("result:\n");
 
114
    debugPrintNfa( p );
 
115
    return 1;
 
116
}
 
117
 
 
118
void regexp_errorMess() {
 
119
  regex a,b,c;
 
120
 
 
121
  a = rexFromString(2,"abcdefg"); // only a, b allowed
 
122
  b = rexFromString(2,"aUbUc[;'{"); // illegal char
 
123
  c = rexFromString(2,"Uab");//illegal syntax
 
124
}
 
125
 
 
126
int main(int argc, char **argv) {
 
127
 
 
128
  initbuf();
 
129
  printf("libtest\n");
 
130
  
 
131
  constr_rexFromString();
 
132
  transf_genrex2nfa( r1 );
 
133
  transf_nfa2dfa();
 
134
  transf_dfa2mindfa();
 
135
  transf_dfa2mon();
 
136
 
 
137
  /*
 
138
  clone_nfa( n1 );
 
139
  clone_dfa( d1 );
 
140
  
 
141
  regexp_errorMess();
 
142
  */
 
143
  return 0;
 
144
  // todo: freeing
 
145
}