X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=src%2Flanguage%2Ftests%2Fmoments-test.c;h=f5fc858dd4d2b130f0af647f14ad7483e92dc311;hb=refs%2Fbuilds%2F190%2Fpspp;hp=a89b50d1e9e7360e4ff8e20c0c1df5f7db92de9b;hpb=8021cf8974a46fe82af7b8952e448c0ea6858a48;p=pspp
diff --git a/src/language/tests/moments-test.c b/src/language/tests/moments-test.c
index a89b50d1e9..f5fc858dd4 100644
--- a/src/language/tests/moments-test.c
+++ b/src/language/tests/moments-test.c
@@ -1,20 +1,18 @@
-/* PSPP - computes sample statistics.
- Copyright (C) 1997-9, 2000 Free Software Foundation, Inc.
+/* PSPP - a program for statistical analysis.
+ Copyright (C) 1997-9, 2000, 2010 Free Software Foundation, Inc.
- 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 of the
- License, or (at your option) any later version.
+ 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 3 of the License, 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.
+ 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., 51 Franklin Street, Fifth Floor, Boston, MA
- 02110-1301, USA. */
+ along with this program. If not, see . */
#include
#include
@@ -30,7 +28,7 @@
#define _(msgid) gettext (msgid)
static bool
-read_values (struct lexer *lexer, double **values, double **weights, size_t *cnt)
+read_values (struct lexer *lexer, double **values, double **weights, size_t *cnt)
{
size_t cap = 0;
@@ -42,7 +40,7 @@ read_values (struct lexer *lexer, double **values, double **weights, size_t *cnt
double value = lex_tokval (lexer);
double weight = 1.;
lex_get (lexer);
- if (lex_match (lexer, '*'))
+ if (lex_match (lexer, T_ASTERISK))
{
if (!lex_is_number (lexer))
{
@@ -53,7 +51,7 @@ read_values (struct lexer *lexer, double **values, double **weights, size_t *cnt
lex_get (lexer);
}
- if (*cnt >= cap)
+ if (*cnt >= cap)
{
cap = 2 * (cap + 8);
*values = xnrealloc (*values, cap, sizeof **values);
@@ -69,7 +67,7 @@ read_values (struct lexer *lexer, double **values, double **weights, size_t *cnt
}
int
-cmd_debug_moments (struct lexer *lexer, struct dataset *ds UNUSED)
+cmd_debug_moments (struct lexer *lexer, struct dataset *ds UNUSED)
{
int retval = CMD_FAILURE;
double *values = NULL;
@@ -81,51 +79,50 @@ cmd_debug_moments (struct lexer *lexer, struct dataset *ds UNUSED)
if (lex_match_id (lexer, "ONEPASS"))
two_pass = 0;
- if (lex_token (lexer) != '/')
+ if (lex_token (lexer) != T_SLASH)
{
- lex_force_match (lexer, '/');
+ lex_force_match (lexer, T_SLASH);
goto done;
}
- fprintf (stderr, "%s => ", lex_rest_of_line (lexer));
lex_get (lexer);
- if (two_pass)
+ if (two_pass)
{
struct moments *m = NULL;
-
+
m = moments_create (MOMENT_KURTOSIS);
- if (!read_values (lexer, &values, &weights, &cnt))
+ if (!read_values (lexer, &values, &weights, &cnt))
{
moments_destroy (m);
- goto done;
+ goto done;
}
for (i = 0; i < cnt; i++)
- moments_pass_one (m, values[i], weights[i]);
+ moments_pass_one (m, values[i], weights[i]);
for (i = 0; i < cnt; i++)
moments_pass_two (m, values[i], weights[i]);
moments_calculate (m, &weight, &M[0], &M[1], &M[2], &M[3]);
moments_destroy (m);
}
- else
+ else
{
struct moments1 *m = NULL;
-
+
m = moments1_create (MOMENT_KURTOSIS);
- if (!read_values (lexer, &values, &weights, &cnt))
+ if (!read_values (lexer, &values, &weights, &cnt))
{
moments1_destroy (m);
- goto done;
+ goto done;
}
for (i = 0; i < cnt; i++)
moments1_add (m, values[i], weights[i]);
moments1_calculate (m, &weight, &M[0], &M[1], &M[2], &M[3]);
moments1_destroy (m);
}
-
+
fprintf (stderr, "W=%.3f", weight);
- for (i = 0; i < 4; i++)
+ for (i = 0; i < 4; i++)
{
- fprintf (stderr, " M%d=", (int) i + 1);
+ fprintf (stderr, " M%zu=", i + 1);
if (M[i] == SYSMIS)
fprintf (stderr, "sysmis");
else if (fabs (M[i]) <= 0.0005)
@@ -136,7 +133,7 @@ cmd_debug_moments (struct lexer *lexer, struct dataset *ds UNUSED)
fprintf (stderr, "\n");
retval = lex_end_of_command (lexer);
-
+
done:
free (values);
free (weights);