Selaa lähdekoodia

Merge pull request 'JJL' (#2) from JJL into master

Reviewed-on: #2
master
佳林 酒 6 päivää sitten
vanhempi
commit
3257609a3f
5 muutettua tiedostoa jossa 15 lisäystä ja 58 poistoa
  1. +1
    -1
      .gitignore
  2. +6
    -0
      JJL.c
  3. +7
    -0
      JJL.h
  4. +0
    -57
      UnitTest1.cpp
  5. +1
    -0
      readme.txt

+ 1
- 1
.gitignore Näytä tiedosto

@@ -1 +1 @@
.vscode/
patch/

+ 6
- 0
JJL.c Näytä tiedosto

@@ -10,6 +10,12 @@ int sub(int a,int b)
return a-b;
}

void my_printf(int a)
{
printf("\r\n\r\n%d\r\n\r\n",a);
}


int main()
{
printf("hello world!");


+ 7
- 0
JJL.h Näytä tiedosto

@@ -0,0 +1,7 @@
#include <iostream>

using namespace std;

void my_printf(int a);



+ 0
- 57
UnitTest1.cpp Näytä tiedosto

@@ -1,57 +0,0 @@
#include "pch.h"
#include "CppUnitTest.h"
#include "test.h"
#include <assert.h>
#include <chrono>
#include <ctime>
#include <cstdlib>
using namespace Microsoft::VisualStudio::CppUnitTestFramework;

void GenerateRandomArray(vector<int>& a,int sum)
{
srand(time(0)); // 使用当前时间作为种子
for (int i = 0; i < sum; i++) {
a.push_back(i);
}
}


namespace UnitTest1
{
TEST_CLASS(UnitTest1)
{
public:
TEST_METHOD(TestMethod1)
{
vector<int> arr = { 5,8,4,3,9,1 };
const vector<int> expect = { 1,3,4,5,8,9 };
selectionSort(arr);
for(int i= 0;i < arr.size();i++)
{
Assert::AreEqual(expect.at(i), arr.at(i));
}
}
TEST_METHOD(TestEmptyArr)
{
vector<int> arr = {};
selectionSort(arr);
Assert::IsTrue(true);
}
BEGIN_TEST_METHOD_ATTRIBUTE(TestRunTime)
TEST_METHOD_ATTRIBUTE(L"RUN","TIME")
END_TEST_METHOD_ATTRIBUTE(TestRunTime)
TEST_METHOD(TestRunTime)
{
vector<int> arr;
GenerateRandomArray(arr, 10000); // 生成随机数组
auto start = std::chrono::high_resolution_clock::now();
selectionSort(arr);
auto end = std::chrono::high_resolution_clock::now();
auto duration = std::chrono::duration_cast<std::chrono::milliseconds>(end - start);
Logger::WriteMessage(("Time: " + std::to_string(duration.count()) + "ms").c_str());
Assert::IsTrue(duration.count() < 10000); // 设定阈值
}
};
}

+ 1
- 0
readme.txt Näytä tiedosto

@@ -0,0 +1 @@
什么也没有

Ladataan…
Peruuta
Tallenna