]> sourceware.org Git - systemtap.git/commitdiff
\18005-09-23 Martin Hunt <hunt@redhat.com>
authorhunt <hunt>
Fri, 23 Sep 2005 07:43:28 +0000 (07:43 +0000)
committerhunt <hunt>
Fri, 23 Sep 2005 07:43:28 +0000 (07:43 +0000)
* maps/map.test: Add sort results.
* maps/sort.c: New test.

runtime/tests/ChangeLog
runtime/tests/maps/map.test
runtime/tests/maps/sort.c [new file with mode: 0644]

index d490b4ea6dae1c3e2c30183de621b8ab29e3e4a5..d18bfacf66712797be475d8a54645c5f74a6e267 100644 (file)
@@ -1,3 +1,8 @@
+2005-09-23  Martin Hunt  <hunt@redhat.com>
+
+       * maps/map.test: Add sort results.
+       * maps/sort.c: New test.
+
 2005-09-14  Martin Hunt  <hunt@redhat.com>
 
        * maps/ii.c (main): Add test for _stp_map_clear().
index 88c097a397790e21d3432e3d9fbed96b41422d6e..118cb75e5fc87c1033dec9a8a37bbfa93edef9a1 100644 (file)
@@ -444,6 +444,153 @@ map[3, Chicago, IL, 2000] = 8272768
 3. The population of Chicago, IL in 2000 was 8272768
 }
 
+test map_sort {Test of sorting} -setup {
+        exec gcc $CFLAGS -I $KPATH -I $PATH -I $MPATH -o test sort.c
+} -body {
+       exec ./test
+} -result {sorting from A-Z on value
+Boston -> 5 5 Massachusetts
+Carson City -> 7 8 Nevada
+Columbus -> 1 2 Ohio
+Des Moines -> 8 8 Iowa
+Montpelier -> 2 2 Vermont
+Olympia -> 5 6 Washington
+Raleigh -> -1 9 North Carolina
+Sacramento -> 3 4 California
+Salem -> 7 8 Oregon
+Santa Fe -> 1 4 New Mexico
+
+
+sorting from Z-A on value
+Santa Fe -> 1 4 New Mexico
+Salem -> 7 8 Oregon
+Sacramento -> 3 4 California
+Raleigh -> -1 9 North Carolina
+Olympia -> 5 6 Washington
+Montpelier -> 2 2 Vermont
+Des Moines -> 8 8 Iowa
+Columbus -> 1 2 Ohio
+Carson City -> 7 8 Nevada
+Boston -> 5 5 Massachusetts
+
+
+sorting from low to high on key 1
+-1 9 North Carolina -> Raleigh
+1 4 New Mexico -> Santa Fe
+1 2 Ohio -> Columbus
+2 2 Vermont -> Montpelier
+3 4 California -> Sacramento
+5 6 Washington -> Olympia
+5 5 Massachusetts -> Boston
+7 8 Oregon -> Salem
+7 8 Nevada -> Carson City
+8 8 Iowa -> Des Moines
+
+
+sorting from high to low on key 1
+8 8 Iowa -> Des Moines
+7 8 Oregon -> Salem
+7 8 Nevada -> Carson City
+5 6 Washington -> Olympia
+5 5 Massachusetts -> Boston
+3 4 California -> Sacramento
+2 2 Vermont -> Montpelier
+1 4 New Mexico -> Santa Fe
+1 2 Ohio -> Columbus
+-1 9 North Carolina -> Raleigh
+
+
+sorting from low to high on key 2
+2 2 Vermont -> Montpelier
+1 2 Ohio -> Columbus
+3 4 California -> Sacramento
+1 4 New Mexico -> Santa Fe
+5 5 Massachusetts -> Boston
+5 6 Washington -> Olympia
+8 8 Iowa -> Des Moines
+7 8 Oregon -> Salem
+7 8 Nevada -> Carson City
+-1 9 North Carolina -> Raleigh
+
+
+sorting from high to low on key 2
+-1 9 North Carolina -> Raleigh
+8 8 Iowa -> Des Moines
+7 8 Oregon -> Salem
+7 8 Nevada -> Carson City
+5 6 Washington -> Olympia
+5 5 Massachusetts -> Boston
+3 4 California -> Sacramento
+1 4 New Mexico -> Santa Fe
+2 2 Vermont -> Montpelier
+1 2 Ohio -> Columbus
+
+
+sorting from low to high on key 3
+California             3 4 -> Sacramento
+Iowa           8 8 -> Des Moines
+Massachusetts          5 5 -> Boston
+Nevada         7 8 -> Carson City
+New Mexico             1 4 -> Santa Fe
+North Carolina         -1 9 -> Raleigh
+Ohio           1 2 -> Columbus
+Oregon         7 8 -> Salem
+Vermont                2 2 -> Montpelier
+Washington             5 6 -> Olympia
+
+
+sorting from high to low on key 3
+Washington             5 6 -> Olympia
+Vermont                2 2 -> Montpelier
+Oregon         7 8 -> Salem
+Ohio           1 2 -> Columbus
+North Carolina         -1 9 -> Raleigh
+New Mexico             1 4 -> Santa Fe
+Nevada         7 8 -> Carson City
+Massachusetts          5 5 -> Boston
+Iowa           8 8 -> Des Moines
+California             3 4 -> Sacramento
+
+
+top 3 alphabetical by value
+Boston -> 5 5 Massachusetts
+Carson City -> 7 8 Nevada
+Columbus -> 1 2 Ohio
+
+
+bottom 2 alphabetical by value
+Santa Fe -> 1 4 New Mexico
+Salem -> 7 8 Oregon
+
+
+top 5 sorted by key 1
+8 8 Iowa -> Des Moines
+7 8 Oregon -> Salem
+7 8 Nevada -> Carson City
+5 6 Washington -> Olympia
+5 5 Massachusetts -> Boston
+
+
+bottom 5 sorted by key 1
+-1 9 North Carolina -> Raleigh
+1 4 New Mexico -> Santa Fe
+1 2 Ohio -> Columbus
+2 2 Vermont -> Montpelier
+3 4 California -> Sacramento
+
+sorted by population from low to high
+Nicosia is the capitol of Cyprus and the nerd population is -1
+Valletta is the capitol of Malta and the nerd population is 1
+Riga is the capitol of Latvia and the nerd population is 135786
+Sofia is the capitol of Bulgaria and the nerd population is 138740
+
+sorted by population from high to low
+Sofia is the capitol of Bulgaria and the nerd population is 138740
+Riga is the capitol of Latvia and the nerd population is 135786
+Valletta is the capitol of Malta and the nerd population is 1
+Nicosia is the capitol of Cyprus and the nerd population is -1
+}
+
 exec rm test
 
 cleanupTests
diff --git a/runtime/tests/maps/sort.c b/runtime/tests/maps/sort.c
new file mode 100644 (file)
index 0000000..6a9b15b
--- /dev/null
@@ -0,0 +1,142 @@
+#include "runtime.h"
+
+/* torture test of map formatting */
+#define NEED_INT64_VALS
+#define NEED_STRING_VALS
+#define NEED_STAT_VALS
+
+#define KEY1_TYPE INT64
+#define KEY2_TYPE INT64
+#define KEY3_TYPE STRING
+#include "map-keys.c"
+
+#define KEY1_TYPE STRING
+#define KEY2_TYPE STRING
+#include "map-keys.c"
+
+#include "map.c"
+
+int main ()
+{
+  MAP mapiis = _stp_map_new_int64_int64_str(10, STRING);
+
+  /* try to crash the sorts with sorting an empty list */
+  _stp_map_sort (mapiis, 0, -1);
+  _stp_map_sort (mapiis, 0, 1);
+  _stp_map_sortn (mapiis, 3, 0, -1);
+  _stp_map_sortn (mapiis, 0, 0, -1);
+
+  /* load some test data */
+  _stp_map_key_int64_int64_str (mapiis, 3,4,"California");
+  _stp_map_add_str (mapiis, "Sacramento" );
+  _stp_map_key_int64_int64_str (mapiis, 5,6,"Washington");
+  _stp_map_set_str (mapiis, "Olympia" );
+  _stp_map_key_int64_int64_str (mapiis, 7,8,"Oregon");
+  _stp_map_set_str (mapiis, "Salem" );
+  _stp_map_key_int64_int64_str (mapiis, 7,8,"Nevada");
+  _stp_map_set_str (mapiis, "Carson City" );
+  _stp_map_key_int64_int64_str (mapiis, 1, 4,"New Mexico");
+  _stp_map_set_str (mapiis, "Santa Fe" );
+  _stp_map_key_int64_int64_str (mapiis, -1,9,"North Carolina");
+  _stp_map_set_str (mapiis, "Raleigh" );
+  _stp_map_key_int64_int64_str (mapiis, 5,5,"Massachusetts");
+  _stp_map_set_str (mapiis, "Boston" );
+  _stp_map_key_int64_int64_str (mapiis, 2,2,"Vermont");
+  _stp_map_set_str (mapiis, "Montpelier" );
+  _stp_map_key_int64_int64_str (mapiis, 8,8,"Iowa");
+  _stp_map_set_str (mapiis, "Des Moines" );
+  _stp_map_key_int64_int64_str (mapiis, 1,2,"Ohio");
+  _stp_map_set_str (mapiis, "Columbus" );
+
+  _stp_printf("sorting from A-Z on value\n");
+  _stp_map_sort (mapiis, 0, -1);
+  _stp_map_print (mapiis, "%s -> %1d %2d %3s");
+
+  _stp_printf("\nsorting from Z-A on value\n");
+  _stp_map_sort (mapiis, 0, 1);
+  _stp_map_print (mapiis, "%s -> %1d %2d %3s");
+
+  _stp_printf("\nsorting from low to high on key 1\n");  
+  _stp_map_sort (mapiis, 1, -1);
+  _stp_map_print (mapiis, "%1d %2d %3s -> %s");
+
+  _stp_printf("\nsorting from high to low on key 1\n");  
+  _stp_map_sort (mapiis, 1, 1);
+  _stp_map_print (mapiis, "%1d %2d %3s -> %s");
+
+  _stp_printf("\nsorting from low to high on key 2\n");  
+  _stp_map_sort (mapiis, 2, -1);
+  _stp_map_print (mapiis, "%1d %2d %3s -> %s");
+
+  _stp_printf("\nsorting from high to low on key 2\n");  
+  _stp_map_sort (mapiis, 2, 1);
+  _stp_map_print (mapiis, "%1d %2d %3s -> %s");
+
+
+  _stp_printf("\nsorting from low to high on key 3\n");  
+  _stp_map_sort (mapiis, 3, -1);
+  _stp_map_print (mapiis, "%3s\t\t%1d %2d -> %s");
+
+  _stp_printf("\nsorting from high to low on key 3\n");  
+  _stp_map_sort (mapiis, 3, 1);
+  _stp_map_print (mapiis, "%3s\t\t%1d %2d -> %s");
+
+
+
+  _stp_printf("\ntop 3 alphabetical by value\n");
+  _stp_map_sortn (mapiis, 3, 0, -1);
+  _stp_map_printn (mapiis, 3, "%s -> %1d %2d %3s");
+
+  _stp_printf("\nbottom 2 alphabetical by value\n");
+  _stp_map_sortn (mapiis, 2, 0, 1);
+  _stp_map_printn (mapiis, 2, "%s -> %1d %2d %3s");
+
+
+  _stp_printf("\ntop 5 sorted by key 1\n");
+  _stp_map_sortn (mapiis, 5, 1, 1);
+  _stp_map_printn (mapiis, 5, "%1d %2d %3s -> %s");
+  _stp_printf("\nbottom 5 sorted by key 1\n");
+  _stp_map_sortn (mapiis, 5, 1, -1);
+  _stp_map_printn (mapiis, 5, "%1d %2d %3s -> %s");
+
+  MAP mapss = _stp_map_new_str_str(4, INT64);
+  _stp_map_key_str_str (mapss, "Riga", "Latvia");
+  _stp_map_set_int64 (mapss, 135786);
+  _stp_map_key_str_str (mapss, "Sofia", "Bulgaria");
+  _stp_map_set_int64 (mapss, 138740);
+  _stp_map_key_str_str (mapss, "Valletta", "Malta");
+  _stp_map_set_int64 (mapss, 1);
+  _stp_map_key_str_str (mapss, "Nicosia", "Cyprus");
+  _stp_map_set_int64 (mapss, -1);
+
+  _stp_printf("sorted by population from low to high\n");
+  _stp_map_sort (mapss, 0, -1);
+  _stp_map_print (mapss, "%1s is the capitol of %2s and the nerd population is %d");
+  _stp_printf("sorted by population from high to low\n");
+  _stp_map_sort (mapss, 0, 1);
+  _stp_map_print (mapss, "%1s is the capitol of %2s and the nerd population is %d");
+
+#if 0
+  MAP mapsst = _stp_map_new_str_str(4, HSTAT_LINEAR, 0, 100, 10 );
+  int i,j;
+
+  _stp_map_key_str_str (mapsst, "Riga", "Latvia");
+  for (i = 0; i < 100; i++)
+    for (j = 0; j <= i*10 ; j++ )
+      _stp_map_add_int64 (mapsst, i);
+  
+  _stp_map_key_str_str (mapsst, "Sofia", "Bulgaria");
+  for (i = 0; i < 10; i++)
+    for (j = 0; j < 10 ; j++ )
+      _stp_map_add_int64 (mapsst, j * i );
+
+  _stp_map_key_str_str (mapsst, "Valletta", "Malta");
+  for (i = 0; i < 100; i += 10)
+    for (j = 0; j < i/10 ; j++ )  
+      _stp_map_add_int64 (mapsst, i);
+  
+  _stp_map_print (mapsst, "Bogons per packet for %1s\ncount:%C  sum:%S  avg:%A  min:%m  max:%M\n%H");
+#endif
+
+  return 0;
+}
This page took 0.033535 seconds and 5 git commands to generate.