1131099Ssobomax/*- 2131099Ssobomax * Copyright (C) 2004 Maxim Sobolev <sobomax@FreeBSD.org> 3131099Ssobomax * All rights reserved. 4131099Ssobomax * 5131099Ssobomax * Redistribution and use in source and binary forms, with or without 6131099Ssobomax * modification, are permitted provided that the following conditions 7131099Ssobomax * are met: 8131099Ssobomax * 1. Redistributions of source code must retain the above copyright 9131099Ssobomax * notice, this list of conditions and the following disclaimer. 10131099Ssobomax * 2. Redistributions in binary form must reproduce the above copyright 11131099Ssobomax * notice, this list of conditions and the following disclaimer in the 12131099Ssobomax * documentation and/or other materials provided with the distribution. 13131099Ssobomax * 14131099Ssobomax * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15131099Ssobomax * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16131099Ssobomax * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17131099Ssobomax * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18131099Ssobomax * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19131099Ssobomax * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20131099Ssobomax * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21131099Ssobomax * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22131099Ssobomax * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23131099Ssobomax * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24131099Ssobomax * SUCH DAMAGE. 25131099Ssobomax */ 26131099Ssobomax 27131099Ssobomax/* 28131099Ssobomax * Test for mergesort() routine. 29131099Ssobomax */ 30131099Ssobomax 31131099Ssobomax#include <sys/cdefs.h> 32131099Ssobomax__FBSDID("$FreeBSD: releng/10.2/tools/regression/lib/libc/stdlib/test-mergesort.c 137587 2004-11-11 19:47:55Z nik $"); 33131099Ssobomax 34131099Ssobomax#include <assert.h> 35131099Ssobomax#include <stdio.h> 36131099Ssobomax#include <stdlib.h> 37131099Ssobomax 38131099Ssobomax#include "test-sort.h" 39131099Ssobomax 40131099Ssobomaxint 41131099Ssobomaxmain(int argc, char *argv[]) 42131099Ssobomax{ 43131099Ssobomax int i, j; 44131099Ssobomax int testvector[IVEC_LEN]; 45131099Ssobomax int sresvector[IVEC_LEN]; 46131099Ssobomax 47137587Snik printf("1..1\n"); 48131099Ssobomax for (j = 2; j < IVEC_LEN; j++) { 49131099Ssobomax /* Populate test vectors */ 50131099Ssobomax for (i = 0; i < j; i++) 51131099Ssobomax testvector[i] = sresvector[i] = initvector[i]; 52131099Ssobomax 53131099Ssobomax /* Sort using mergesort(3) */ 54131099Ssobomax mergesort(testvector, j, sizeof(testvector[0]), sorthelp); 55131099Ssobomax /* Sort using reference slow sorting routine */ 56131099Ssobomax ssort(sresvector, j); 57131099Ssobomax 58131099Ssobomax /* Compare results */ 59131099Ssobomax for (i = 0; i < j; i++) 60131099Ssobomax assert(testvector[i] == sresvector[i]); 61131099Ssobomax } 62131099Ssobomax 63137587Snik printf("ok 1 - mergesort\n"); 64131099Ssobomax 65131099Ssobomax return(0); 66131099Ssobomax} 67