This repository has been archived by the owner on Sep 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
348828a
commit 72ef7b4
Showing
11 changed files
with
168 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#ifndef __DSLINGS_HPP__D2DS | ||
#define __DSLINGS_HPP__D2DS | ||
|
||
namespace d2ds { | ||
// show your code | ||
|
||
|
||
|
||
|
||
|
||
|
||
/* | ||
class MaxValue { | ||
public: | ||
MaxValue(int val) { | ||
__mVal = val; | ||
} | ||
int get() { | ||
return __mVal; | ||
} | ||
void set(int val) { | ||
if (val > __mVal) | ||
__mVal = val; | ||
} | ||
private: | ||
int __mVal; | ||
}; | ||
*/ | ||
|
||
|
||
} | ||
|
||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#include <tests/common.hpp> | ||
|
||
#include <exercises/array/Array.hpp> | ||
|
||
int main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#include <tests/common.hpp> | ||
|
||
#include <exercises/array/Array.hpp> | ||
|
||
int main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
#include <tests/common.hpp> | ||
|
||
#include <exercises/array/Array.hpp> | ||
|
||
int main() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#ifndef __COMMON_HPP__D2DS | ||
#define __COMMON_HPP__D2DS | ||
|
||
#include <iostream> | ||
#include <random> | ||
#include <cassert> | ||
|
||
#define DeleteTheAssertToContinue() assert(false) | ||
|
||
#endif |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
// dslings.0.cpp - readonly | ||
// | ||
// 描述: | ||
// 通过实现一个MaxVal类型(保存最大值), 来介绍dslings的"编译器驱动开发" | ||
// 即根据编译器的错误提示来完成这个训练流程的演示Demo, 并且通常为了降低难度会把一个'数据结构'的实现分成多个检测模块. | ||
// 如: dslings.0.cpp dslings.1.cpp dslings.2.cpp | ||
// | ||
// 目标/要求: | ||
// - 不修改该代码检测文件 | ||
// - 在exercises/dslings.hpp中完成你的代码设计 | ||
// - 通过所有编译器检测 和 断言 | ||
// | ||
|
||
#include <tests/common.hpp> | ||
|
||
#include <exercises/dslings.hpp> | ||
|
||
int main() { | ||
|
||
d2ds::MaxValue mVal(2); | ||
|
||
assert(mVal.get() == 2); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// dslings.1.cpp - readonly | ||
// | ||
// 描述: | ||
// 通过实现一个MaxVal类型(保存最大值), 来介绍dslings的"编译器驱动开发" | ||
// 即根据编译器的错误提示来完成这个训练流程的演示Demo, 并且通常为了降低难度会把一个'数据结构'的实现分成多个检测模块. | ||
// 如: dslings.0.cpp dslings.1.cpp dslings.2.cpp | ||
// | ||
// 目标/要求: | ||
// - 不修改该代码检测文件 | ||
// - 在exercises/dslings.hpp中完成你的代码设计 | ||
// - 通过所有编译器检测 和 断言 | ||
// | ||
|
||
#include <tests/common.hpp> | ||
|
||
#include <exercises/dslings.hpp> | ||
|
||
int main() { | ||
|
||
d2ds::MaxValue mVal(2); | ||
|
||
assert(mVal.get() == 2); | ||
|
||
mVal.set(-1); | ||
assert(mVal.get() == 2); | ||
|
||
mVal.set(100); | ||
assert(mVal.get() == 100); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// dslings.2.cpp - readonly | ||
// | ||
// 描述: | ||
// 通过实现一个MaxVal类型(保存最大值), 来介绍dslings的"编译器驱动开发" | ||
// 即根据编译器的错误提示来完成这个训练流程的演示Demo, 并且通常为了降低难度会把一个'数据结构'的实现分成多个检测模块. | ||
// 如: dslings.0.cpp dslings.1.cpp dslings.2.cpp | ||
// | ||
// 目标/要求: | ||
// - 不修改该代码检测文件 | ||
// - 在exercises/dslings.hpp中完成你的代码设计 | ||
// - 通过所有编译器检测 和 断言 | ||
// | ||
|
||
#include <tests/common.hpp> | ||
|
||
#include <exercises/dslings.hpp> | ||
|
||
int main() { | ||
|
||
d2ds::MaxValue mVal(2); | ||
|
||
assert(mVal.get() == 2); | ||
|
||
mVal.set(-1); | ||
assert(mVal.get() == 2); | ||
|
||
mVal.set(100); | ||
assert(mVal.get() == 100); | ||
|
||
// random test | ||
std::random_device rd; | ||
std::mt19937 gen(rd()); // 使用随机设备作为种子 | ||
std::uniform_int_distribution<int> dis(0, 200); // 定义范围为 [0, 200] 的均匀分布 | ||
|
||
int currMaxVal = mVal.get(); | ||
for (int i = 0; i < 10; i++) { | ||
int randomNum = dis(gen); | ||
int newMaxVal = currMaxVal > randomNum ? currMaxVal : randomNum; | ||
mVal.set(randomNum); | ||
assert(mVal.get() == newMaxVal); | ||
currMaxVal = mVal.get(); | ||
} | ||
|
||
std::cout << "hello, dslings..." << std::endl; | ||
|
||
DeleteTheAssertToContinue(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters