Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
TestTree23.cpp
00001 /************************************************************************************** 00002 * Copyright (c) 2016, Tomoaki Yamaguchi 00003 * 00004 * All rights reserved. This program and the accompanying materials 00005 * are made available under the terms of the Eclipse Public License v1.0 00006 * and Eclipse Distribution License v1.0 which accompany this distribution. 00007 * 00008 * The Eclipse Public License is available at 00009 * http://www.eclipse.org/legal/epl-v10.html 00010 * and the Eclipse Distribution License is available at 00011 * http://www.eclipse.org/org/documents/edl-v10.php. 00012 * 00013 * Contributors: 00014 * Tomoaki Yamaguchi - initial API and implementation 00015 **************************************************************************************/ 00016 #include "TestTree23.h" 00017 #include <stdio.h> 00018 #include <string> 00019 #include <cassert> 00020 00021 using namespace std; 00022 using namespace MQTTSNGW; 00023 00024 TestTree23::TestTree23() 00025 { 00026 00027 } 00028 00029 TestTree23::~TestTree23() 00030 { 00031 00032 } 00033 00034 void TestTree23::test(void) 00035 { 00036 int N = 100; 00037 00038 Key* r1[100]; 00039 Integer* r2[100]; 00040 00041 for ( int i = 0; i < N; i++) 00042 { 00043 char buff[5]; 00044 sprintf(buff,"%d", i); 00045 r1[i] = new Key(string(buff)); 00046 r2[i] = new Integer(i); 00047 this->add(r1[i], r2[i]); 00048 } 00049 00050 for ( int i = 0; i < N; i++) 00051 { 00052 Integer* rc = this->getVal(r1[i]); 00053 //printf("key=%d val=%d\n", i, rc->_val); 00054 assert(i == rc->_val); 00055 } 00056 00057 for ( int i = 20; i < 50; i++) 00058 { 00059 this->remove(r1[i]); 00060 //printf("key=%d str=%s\n", i, r1[i]->_key.c_str()); 00061 } 00062 00063 for ( int i = 0; i < 20; i++) 00064 { 00065 bool rc = this->find(r1[i]); 00066 assert(rc == true); 00067 //printf("key=%d find=%d\n", i, rc); 00068 Integer* val = this->getVal(r1[i]); 00069 //printf("key=%d val=%d\n", i, val->_val); 00070 assert(val->_val == i); 00071 } 00072 for ( int i = 20; i < 50; i++ ) 00073 { 00074 bool rc = this->find(r1[i]); 00075 assert(rc == false); 00076 //printf("key=%d find=%d\n", i, rc); 00077 Integer* val = this->getVal(r1[i]); 00078 assert(val == 0); 00079 } 00080 for ( int i = 50; i < N; i++) 00081 { 00082 bool rc = this->find(r1[i]); 00083 assert(rc == true); 00084 //printf("key=%d find=%d\n", i, rc); 00085 Integer* val = this->getVal(r1[i]); 00086 //printf("key=%d val=%d\n", i, val->_val); 00087 assert(val->_val == i); 00088 } 00089 printf("[ OK ]\n"); 00090 } 00091
Generated on Wed Jul 13 2022 10:46:03 by
1.7.2