no message

master
zcy 2023-05-21 23:19:31 +08:00
parent 3b3a50a07c
commit 2c6edbbb54
1 changed files with 120 additions and 0 deletions

View File

@ -0,0 +1,120 @@
/*
* @Author: your name
* @Date: 2021-10-09 10:03:45
* @LastEditTime: 2021-12-01 14:48:38
* @LastEditors: your name
* @Description: koroFileHeader : https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
* @FilePath: \cpp11\template.cpp
*/
#include "iostream"
#include <vector>
#include "pattern/ringbuffer.hpp"
#include <tuple>
#include <math.h>
using namespace std;
void TestShuffle(){
int in[1024];
for(int j = 0;j < 1024;j++){
in[j] = j;
}
int out[1024];
RingBuffer<int> ring(1024,false);
int size = 0;
for(int i = 0;i < 10;i++){
int tmp = rand();
std::cout<<std::endl<<"----------------------------------"<<"\r\n";
switch (tmp%3)
{
case 1:
size = rand()%1024;
ring.Add(in,size);
std::cout<<"add "<<size<<" x.Length():" << ring.Length() << " "<<std::endl;
break;
case 2:
size = rand()%1024;
ring.TakeBack(out,size);
std::cout<<"take back"<<size<<" x.Length():" << ring.Length() << " "<<std::endl;
break;
case 0:
size = rand()%1024;
ring.TakeFront(out,size);
std::cout<<"take front"<<size<<" x.Length():" << ring.Length() << " "<<std::endl;
break;
default:
break;
}
}
}
void TestRingBufferTakeBack(){
int in[1024];
int out[1024];
for(int i = 0;i < 1024;i ++){
in[i] = i;
}
RingBuffer<int> x(1024,false);
for(int i = 0;i < 10;i++){
std::cout<<std::endl<<"----------------------------------"<<"\r\n";
int ran = rand()%1024;
int ret = x.Add(in,ran);
std::cout<<"add "<<ran<<" x.Length():" << x.Length() << " "<<std::endl;
for(uint32_t i = 0;i < x.Length();i++){
// std::cout<<x.At(i) <<" ";
}
std::cout<<"----------------------------------"<<"\r\n";
int ran2 = rand()%1024;
x.TakeBack(out,ran2);
std::cout<<"take "<<ran2<<" x.Length():" << x.Length() << " "<<std::endl;
for(uint32_t i = 0;i < x.Length();i++){
std::cout<<x.At(i) <<" ";
}
std::cout<<std::endl<<"----------------------------------"<<"\r\n";
}
fflush(stdout);
}
void TestRingBufferTakeFront(){
int in[1024];
int out[1024];
for(int i = 0;i < 1024;i ++){
in[i] = i;
}
RingBuffer<int> x(1024,true);
for(int i = 0;i < 10;i++){
std::cout<<std::endl<<"\r\n----------------------------------"<<"\r\n";
int ran = rand()%1024;
int ret = x.Add(in,ran);
std::cout<<"add "<<ran<<" x.Length():" << x.Length() << " "<<std::endl;
for(uint32_t i = 0;i < x.Length();i++){
std::cout<<x.At(i) <<" ";
}
std::cout<<"\r\n----------------------------------"<<"\r\n";
int ran2 = rand()%1024;
x.TakeFront(out,ran2);
std::cout<<"take "<<ran2<<" x.Length():" << x.Length() << " "<<std::endl;
for(uint32_t i = 0;i < x.Length();i++){
std::cout<<x.At(i) <<" ";
}
std::cout<<std::endl<<"\r\n----------------------------------"<<"\r\n";
}
fflush(stdout);
}
int main() {
// TestRingBufferTakeBack();
TestShuffle();
// TestRingBufferTakeFront();
}