heapsort_test.c (137587) | heapsort_test.c (290538) |
---|---|
1/*- 2 * Copyright (C) 2004 Maxim Sobolev <sobomax@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Test for heapsort() routine. 29 */ 30 31#include <sys/cdefs.h> | 1/*- 2 * Copyright (C) 2004 Maxim Sobolev <sobomax@FreeBSD.org> 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 15 unchanged lines hidden (view full) --- 24 * SUCH DAMAGE. 25 */ 26 27/* 28 * Test for heapsort() routine. 29 */ 30 31#include <sys/cdefs.h> |
32__FBSDID("$FreeBSD: head/tools/regression/lib/libc/stdlib/test-heapsort.c 137587 2004-11-11 19:47:55Z nik $"); | 32__FBSDID("$FreeBSD: head/lib/libc/tests/stdlib/heapsort_test.c 290538 2015-11-08 07:03:17Z ngie $"); |
33 34#include <assert.h> 35#include <stdio.h> 36#include <stdlib.h> 37 38#include "test-sort.h" 39 | 33 34#include <assert.h> 35#include <stdio.h> 36#include <stdlib.h> 37 38#include "test-sort.h" 39 |
40int 41main(int argc, char *argv[]) | 40ATF_TC_WITHOUT_HEAD(heapsort_test); 41ATF_TC_BODY(heapsort_test, tc) |
42{ | 42{ |
43 int i, j; 44 int testvector[IVEC_LEN]; 45 int sresvector[IVEC_LEN]; | 43 int sresvector[IVEC_LEN]; 44 int testvector[IVEC_LEN]; 45 int i, j; |
46 | 46 |
47 printf("1..1\n"); 48 for (j = 2; j < IVEC_LEN; j++) { 49 /* Populate test vectors */ 50 for (i = 0; i < j; i++) 51 testvector[i] = sresvector[i] = initvector[i]; | 47 for (j = 2; j < IVEC_LEN; j++) { 48 /* Populate test vectors */ 49 for (i = 0; i < j; i++) 50 testvector[i] = sresvector[i] = initvector[i]; |
52 | 51 |
53 /* Sort using heapsort(3) */ 54 heapsort(testvector, j, sizeof(testvector[0]), sorthelp); 55 /* Sort using reference slow sorting routine */ 56 ssort(sresvector, j); | 52 /* Sort using heapsort(3) */ 53 heapsort(testvector, j, sizeof(testvector[0]), sorthelp); 54 /* Sort using reference slow sorting routine */ 55 ssort(sresvector, j); |
57 | 56 |
58 /* Compare results */ 59 for (i = 0; i < j; i++) 60 assert(testvector[i] == sresvector[i]); 61 } | 57 /* Compare results */ 58 for (i = 0; i < j; i++) 59 ATF_CHECK_MSG(testvector[i] == sresvector[i], 60 "item at index %d didn't match: %d != %d", 61 i, testvector[i], sresvector[i]); 62 } 63} |
62 | 64 |
63 printf("ok 1 - heapsort\n"); | 65ATF_TP_ADD_TCS(tp) 66{ |
64 | 67 |
65 return(0); | 68 ATF_TP_ADD_TC(tp, heapsort_test); 69 70 return (atf_no_error()); |
66} | 71} |