ALT Linux Team development discussions
 help / color / mirror / Atom feed
From: "Kirill A. Shutsemov" <kirill@shutemov.name>
To: "Dmitry V. Levin" <ldv@altlinux.org>, Alexey Tourbin <at@altlinux.ru>
Cc: "Alexey I. Froloff" <raorn@altlinux.org>,
	devel@lists.altlinux.org, Alexey Gladkov <legion@altlinux.ru>,
	"Kirill A. Shutemov" <kirill@shutemov.name>
Subject: [devel] [PATCH 7/8] set.c: cleanup self-tests
Date: Tue, 16 Nov 2010 17:56:41 +0200
Message-ID: <1289923002-14132-8-git-send-email-kirill@shutemov.name> (raw)
In-Reply-To: <1289923002-14132-1-git-send-email-kirill@shutemov.name>

From: Kirill A. Shutemov <kirill@shutemov.name>

Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
---
 lib/set.c |   94 +++++++++++++++++++++++++++++++++++++++----------------------
 1 files changed, 60 insertions(+), 34 deletions(-)

diff --git a/lib/set.c b/lib/set.c
index b4ed87d..a98e3f8 100644
--- a/lib/set.c
+++ b/lib/set.c
@@ -220,23 +220,29 @@ void test_base62(void)
 	1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
     };
     const int rnd_bitc = sizeof(rnd_bitv);
+    char *base62, *bitv;
+    int i, len, bitc;
+
     /* encode */
-    char base62[encode_base62_size(rnd_bitc)];
-    int len = encode_base62(rnd_bitc, rnd_bitv, base62);
+    base62 = alloca(encode_base62_size(rnd_bitc));
+    len = encode_base62(rnd_bitc, rnd_bitv, base62);
     assert(len > 0);
-    assert(len == (int)strlen(base62));
+    assert(len == (int) strlen(base62));
     fprintf(stderr, "len=%d base62=%s\n", len, base62);
+
     /* The length cannot be shorter than 6 bits per symbol. */
     assert(len >= rnd_bitc / 6);
+
     /* Neither too long: each second character must fill at least 4 bits. */
     assert(len <= rnd_bitc / 2 / 4 + rnd_bitc / 2 / 6 + 1);
+
     /* decode */
-    char bitv[decode_base62_size(base62)];
-    int bitc = decode_base62(base62, bitv);
+    bitv = alloca(decode_base62_size(base62));
+    bitc = decode_base62(base62, bitv);
     fprintf(stderr, "rnd_bitc=%d bitc=%d\n", rnd_bitc, bitc);
     assert(bitc >= rnd_bitc);
+
     /* Decoded bits must match. */
-    int i;
     for (i = 0; i < rnd_bitc; i++)
 	assert(rnd_bitv[i] == bitv[i]);
     /* The remaining bits must be zero bits. */
@@ -402,39 +408,47 @@ static
 void test_golomb(void)
 {
     const unsigned rnd_v[] = {
-	/* do re mi fa sol la si */
 	1, 2, 3, 4, 5, 6, 7,
-	/* koshka sela na taksi */
 	7, 6, 5, 4, 3, 2, 1,
     };
     const int rnd_c = sizeof(rnd_v) / sizeof(*rnd_v);
-    int bpp = 10;
-    int Mshift = encode_golomb_Mshift(rnd_c, bpp);
+    char *bitv;
+    unsigned *v;
+    int bpp, Mshift;
+    int alloc_bitc, bitc;
+    int alloc_c, c, golomb_bpp;
+    int i;
+
+    bpp = 10;
+    Mshift = encode_golomb_Mshift(rnd_c, bpp);
     fprintf(stderr, "rnd_c=%d bpp=%d Mshift=%d\n", rnd_c, bpp, Mshift);
     assert(Mshift > 0);
     assert(Mshift < bpp);
+
     /* encode */
-    int alloc_bitc = encode_golomb_size(rnd_c, Mshift);
+    alloc_bitc = encode_golomb_size(rnd_c, Mshift);
     assert(alloc_bitc > rnd_c);
-    char bitv[alloc_bitc];
-    int bitc = encode_golomb(rnd_c, rnd_v, Mshift, bitv);
+    bitv = alloca(alloc_bitc);
+    bitc = encode_golomb(rnd_c, rnd_v, Mshift, bitv);
     fprintf(stderr, "alloc_bitc=%d bitc=%d\n", alloc_bitc, bitc);
     assert(bitc > rnd_c);
     assert(bitc <= alloc_bitc);
+
     /* decode */
-    int alloc_c = decode_golomb_size(bitc, Mshift);
+    alloc_c = decode_golomb_size(bitc, Mshift);
     assert(alloc_c >= rnd_c);
-    unsigned v[alloc_c];
-    int c = decode_golomb(bitc, bitv, Mshift, v);
+    v = alloca(sizeof(*v) * alloc_c);
+    c = decode_golomb(bitc, bitv, Mshift, v);
     fprintf(stderr, "rnd_c=%d alloc_c=%d c=%d\n", rnd_c, alloc_c, c);
     assert(alloc_c >= c);
+
     /* Decoded values must match. */
     assert(rnd_c == c);
-    int i;
     for (i = 0; i < c; i++)
 	assert(rnd_v[i] == v[i]);
+
     /* At the end of the day, did it save your money? */
-    int golomb_bpp = bitc / c;
+    golomb_bpp = bitc / c;
     fprintf(stderr, "bpp=%d golomb_bpp=%d\n", bpp, golomb_bpp);
     assert(golomb_bpp < bpp);
     fprintf(stderr, "%s: golomb test OK\n", __FILE__);
@@ -480,6 +494,7 @@ void test_delta(void)
 	1, 3, 7, 0
     };
     int c = 3;
+
     encode_delta(c, v);
     assert(v[0] == 1);
     assert(v[1] == 2);
@@ -546,6 +561,7 @@ void test_aux(void)
 {
     unsigned v[] = { 2, 3, 1, 2, 7, 6, 5 };
     int c = sizeof(v) / sizeof(*v);
+
     maskv(c, v, 4 - 1);
     sortv(c, v);
     c = uniqv(c, v);
@@ -711,25 +727,32 @@ void test_set(void)
 	0xb584, 0xb89f, 0xbb40, 0xf39e,
     };
     int rnd_c = sizeof(rnd_v) / sizeof(*rnd_v);
+    char *base62;
+    unsigned *v;
+    int bpp, Mshift;
+    int i, len, rc, c;
+
     /* encode */
-    int bpp = 16;
-    char base62[encode_set_size(rnd_c, bpp)];
-    int len = encode_set(rnd_c, rnd_v, bpp, base62);
+    bpp = 16;
+    base62 = alloca(encode_set_size(rnd_c, bpp));
+    len = encode_set(rnd_c, rnd_v, bpp, base62);
     assert(len > 0);
     fprintf(stderr, "len=%d set=%s\n", len, base62);
+
     /* decode */
-    int Mshift = bpp;
-    int rc = decode_set_init(base62, &bpp, &Mshift);
+    Mshift = bpp;
+    rc = decode_set_init(base62, &bpp, &Mshift);
     assert(rc == 0);
     assert(bpp == 16);
     assert(Mshift < bpp);
-    int c = decode_set_size(base62, Mshift);
+
+    c = decode_set_size(base62, Mshift);
     assert(c >= rnd_c);
-    unsigned v[c];
+    v = alloca(sizeof(*v) * c);
     c = decode_set(base62, Mshift, v);
+
     /* Decoded values must match. */
     assert(c == rnd_c);
-    int i;
     for (i = 0; i < c; i++)
 	assert(v[i] == rnd_v[i]);
     fprintf(stderr, "%s: set test OK\n", __FILE__);
@@ -952,35 +975,38 @@ const char *set_fini(struct set *set, int bpp)
 static
 void test_api(void)
 {
-    struct set *set1 = set_new();
+    struct set *set1, *set2;
+    const char *str10, *str11, *str20, *str21, *str22;
+    int cmp;
+
+    set1 = set_new();
     set_add(set1, "mama");
     set_add(set1, "myla");
     set_add(set1, "ramu");
-    const char *str10 = set_fini(set1, 16);
+    str10 = set_fini(set1, 16);
     fprintf(stderr, "set10=%s\n", str10);
 
-    int cmp;
-    struct set *set2 = set_new();
+    set2 = set_new();
     set_add(set2, "myla");
     set_add(set2, "mama");
-    const char *str20 = set_fini(set2, 16);
+    str20 = set_fini(set2, 16);
     fprintf(stderr, "set20=%s\n", str20);
     cmp = rpmsetcmp(str10, str20);
     assert(cmp == 1);
 
     set_add(set2, "ramu");
-    const char *str21 = set_fini(set2, 16);
+    str21 = set_fini(set2, 16);
     fprintf(stderr, "set21=%s\n", str21);
     cmp = rpmsetcmp(str10, str21);
     assert(cmp == 0);
 
     set_add(set2, "baba");
-    const char *str22 = set_fini(set2, 16);
+    str22 = set_fini(set2, 16);
     cmp = rpmsetcmp(str10, str22);
     assert(cmp == -1);
 
     set_add(set1, "deda");
-    const char *str11 = set_fini(set1, 16);
+    str11 = set_fini(set1, 16);
     cmp = rpmsetcmp(str11, str22);
     assert(cmp == -2);
 
-- 
1.7.3.2



  parent reply	other threads:[~2010-11-16 15:56 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-16 15:56 [devel] [PATCH 0/8] rpm: cleanup set.c and set.h Kirill A. Shutsemov
2010-11-16 15:56 ` [devel] [PATCH 1/8] set.c, set.h: get rid of C++-style comments Kirill A. Shutsemov
2010-11-16 15:56 ` [devel] [PATCH 2/8] set.c: get rid of nested functions Kirill A. Shutsemov
2010-11-16 22:14   ` Dmitry V. Levin
2010-11-16 22:54     ` Kirill A. Shutemov
2010-11-16 23:07       ` Dmitry V. Levin
2010-11-16 23:10         ` Kirill A. Shutemov
2010-11-17 17:55           ` Dmitry V. Levin
2010-11-16 15:56 ` [devel] [PATCH 3/8] set.c: fixup self-test functions declaration Kirill A. Shutsemov
2010-11-16 15:56 ` [devel] [PATCH 4/8] set.c: slightly reformat code to increase its readability Kirill A. Shutsemov
2010-11-16 15:56 ` [devel] [PATCH 5/8] set.c: do not mix declarations and code Kirill A. Shutsemov
2010-11-16 15:56 ` [devel] [PATCH 6/8] set.c: use function-like syntax for sizeof Kirill A. Shutsemov
2010-11-16 15:56 ` Kirill A. Shutsemov [this message]
2010-11-16 15:56 ` [devel] [PATCH 8/8] set.c: update copyright notice Kirill A. Shutsemov
2010-11-22  5:49   ` Alexey Tourbin
2010-11-23  0:48       ` Alexey Tourbin
2010-11-23  0:56         ` Dmitry V. Levin
2010-11-23  1:38           ` Alexey Tourbin
2010-11-23  6:42             ` Kirill A. Shutemov
2010-11-23 11:50               ` Alexey Tourbin
2010-11-25 22:02                 ` Kirill A. Shutemov
2010-11-26 18:03                 ` Michael Shigorin
2010-11-17  6:59 ` [devel] [PATCH 0/8] rpm: cleanup set.c and set.h REAL
2010-11-22  5:40 ` Alexey Tourbin
2010-11-22  7:14   ` Kirill A. Shutemov
2010-11-22  7:38     ` Alexey Tourbin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1289923002-14132-8-git-send-email-kirill@shutemov.name \
    --to=kirill@shutemov.name \
    --cc=at@altlinux.ru \
    --cc=devel@lists.altlinux.org \
    --cc=ldv@altlinux.org \
    --cc=legion@altlinux.ru \
    --cc=raorn@altlinux.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

ALT Linux Team development discussions

This inbox may be cloned and mirrored by anyone:

	git clone --mirror http://lore.altlinux.org/devel/0 devel/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 devel devel/ http://lore.altlinux.org/devel \
		devel@altlinux.org devel@altlinux.ru devel@lists.altlinux.org devel@lists.altlinux.ru devel@linux.iplabs.ru mandrake-russian@linuxteam.iplabs.ru sisyphus@linuxteam.iplabs.ru
	public-inbox-index devel

Example config snippet for mirrors.
Newsgroup available over NNTP:
	nntp://lore.altlinux.org/org.altlinux.lists.devel


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git