gcalctool r2026 - in trunk: . gcalctool
- From: rancell svn gnome org
- To: svn-commits-list gnome org
- Subject: gcalctool r2026 - in trunk: . gcalctool
- Date: Wed, 12 Mar 2008 00:38:23 +0000 (GMT)
Author: rancell
Date: Wed Mar 12 00:38:23 2008
New Revision: 2026
URL: http://svn.gnome.org/viewvc/gcalctool?rev=2026&view=rev
Log:
Bug #135671 - Added initial unit tests
Added:
trunk/gcalctool/unittest.c
trunk/gcalctool/unittest.h
Modified:
trunk/ChangeLog
trunk/gcalctool/Makefile.am
trunk/gcalctool/calctool.c
trunk/gcalctool/functions.h
Modified: trunk/gcalctool/Makefile.am
==============================================================================
--- trunk/gcalctool/Makefile.am (original)
+++ trunk/gcalctool/Makefile.am Wed Mar 12 00:38:23 2008
@@ -33,6 +33,8 @@
parser_mac.h \
gtk.c \
ui.h \
+ unittest.c \
+ unittest.h \
ce_parser.c \
ce_parser.h \
ce_parser.tab.h \
Modified: trunk/gcalctool/calctool.c
==============================================================================
--- trunk/gcalctool/calctool.c (original)
+++ trunk/gcalctool/calctool.c Wed Mar 12 00:38:23 2008
@@ -26,6 +26,7 @@
#include <sys/types.h>
#include "calctool.h"
+#include "unittest.h"
#include "get.h"
#include "display.h"
#include "functions.h"
@@ -619,11 +620,12 @@
* the second is the program version number.
*/
FPRINTF(stderr, _("%s version %s\n\n"), progname, VERSION);
- FPRINTF(stderr, _("Usage: %s: [-D] [-E] [-a accuracy] "), progname);
+ FPRINTF(stderr, _("Usage: %s: [-D] [-E] [-u] [-a accuracy] "), progname);
FPRINTF(stderr, _("\t\t [-?] [-v] [-h]\n"));
exit(1);
}
+
#define INC { argc--; argv++; }
void
@@ -662,6 +664,10 @@
read_str(&v->appname, argv[0]);
}
break;
+
+ case 'u':
+ unittest();
+ break;
case '?' :
case 'v' :
Modified: trunk/gcalctool/functions.h
==============================================================================
--- trunk/gcalctool/functions.h (original)
+++ trunk/gcalctool/functions.h Wed Mar 12 00:38:23 2008
@@ -45,7 +45,7 @@
void do_business();
void do_calc();
void do_lr_calc();
-void do_expression();
+void do_expression(int function, int arg, int cursor);
void do_clear();
void do_clear_entry();
void do_backspace();
Added: trunk/gcalctool/unittest.c
==============================================================================
--- (empty file)
+++ trunk/gcalctool/unittest.c Wed Mar 12 00:38:23 2008
@@ -0,0 +1,122 @@
+
+/* $Header$
+ *
+ * Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#include "unittest.h"
+
+#include "display.h"
+#include "functions.h"
+#include "calctool.h"
+
+static void
+test(char *expression, char *expected, int expected_error)
+{
+ int error;
+ int result[MP_SIZE];
+ char result_str[MAXLINE];
+
+ error = ce_parse(expression, result);
+ if(error != 0 || error != expected_error)
+ {
+ if(error == expected_error)
+ printf("SUCCESS: '%s' -> error %d\n", expression, error);
+ else
+ printf("FAIL: '%s' -> error %d, expected error %d and result '%s'\n", expression, error, expected_error, expected);
+ return;
+ }
+
+ make_fixed(result, result_str, DEC, 10, FALSE);
+ if(strcmp(result_str, expected) != 0)
+ printf("FAIL: '%s' -> '%s', expected '%s'\n", expression, result_str, expected);
+ else
+ printf("SUCCESS: '%s' -> '%s'\n", expression, result_str);
+}
+
+
+void
+test_parser()
+{
+ v->modetype = SCIENTIFIC;
+
+ test("0", "0", 0);
+ test("1", "1", 0);
+ test("+1", "1", 0);
+ test("++1", "1", 0);
+ test("--1", "1", 0);
+ test("255", "255", 0);
+ test("256", "256", 0);
+ test("1.00", "1", 0);
+ test("1.01", "1.01", 0);
+ test("1e9", "1000000000", 0);
+
+ test("0+0", "0", 0);
+ test("1+1", "2", 0);
+ test("2-3", "-1", 0);
+ test("2*3", "6", 0);
+ //FIXME: Need to update mperr() test("1/2", "0.5", 0);
+ //FIXME: Need to update mperr() test("1/0", "", 0);
+ //FIXME: Need to update mperr() test("0/0", "", 0);
+
+ test("1+2*3", "7", 0);
+ test("(1+2)*3", "9", 0);
+
+ test("100%", "1", 0);
+ test("1%", "0.01", 0);
+ test("2^2", "4", 0);
+ test("2^-1", "0.5", 0);
+ test("0!", "1", 0);
+ test("1!", "1", 0);
+ test("5!", "120", 0);
+ //FIXME: Need to update do_factorial() test("0.1!", "", 0);
+ //FIXME: Need to update do_factorial() test("-1!", "", 0);
+
+ test("Sqrt(4)", "2", 0);
+ test("Sqrt(2)", "1.4142135", 0);
+
+ test("Int(3.2)", "3", 0);
+ test("Frac(3.2)", "0.2", 0);
+ test("Int(-3.2)", "-3", 0);
+ test("Frac(-3.2)", "-0.2", 0);
+
+ test("Abs(1)", "1", 0);
+ test("Abs(-1)", "1", 0);
+
+ test("Sin(0)", "0", 0);
+ test("Cos(0)", "1", 0);
+ test("Tan(0)", "0", 0);
+
+ v->ttype = DEG;
+ test("Sin(90)", "1", 0);
+
+ v->ttype = RAD;
+ test("Sin(3.14159/2)", "1", 0);
+
+ v->ttype = GRAD;
+ test("Sin(100)", "1", 0);
+}
+
+
+void
+unittest()
+{
+ test_parser();
+
+ exit(1);
+}
Added: trunk/gcalctool/unittest.h
==============================================================================
--- (empty file)
+++ trunk/gcalctool/unittest.h Wed Mar 12 00:38:23 2008
@@ -0,0 +1,27 @@
+
+/* $Header$
+ *
+ * Copyright (c) 1987-2008 Sun Microsystems, Inc. All Rights Reserved.
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2, or (at your option)
+ * any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ */
+
+#ifndef UNITTEST_H
+#define UNITTEST_H
+
+void unittest();
+
+#endif /* UNITTEST_H */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]