Skip to content

Commit 38ac0e7

Browse files
committed
rename files
1 parent 5759bc1 commit 38ac0e7

File tree

8 files changed

+48
-42
lines changed

8 files changed

+48
-42
lines changed

cpp-algorithm/src/array/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ add_library_target(enumerate_prime_number)
1414
add_library_target(order_element)
1515
add_library_target(random_data_sampling)
1616
add_library_target(replace_element)
17-
add_library_target(trade_stock)
17+
add_library_target(stock_trading)

cpp-algorithm/src/array/benchmark/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,4 @@ add_target_benchmark(enumerate_prime_number_benchmark)
2323
# add_target_benchmark(order_element_benchmark)
2424
add_target_benchmark(random_data_sampling_benchmark)
2525
add_target_benchmark(replace_element_benchmark)
26-
add_target_benchmark(trade_stock_benchmark)
26+
add_target_benchmark(stock_trading_benchmark)

cpp-algorithm/src/array/benchmark/trade_stock_benchmark.cpp renamed to cpp-algorithm/src/array/benchmark/stock_trading_benchmark.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#include "trade_stock.h"
1+
#include "stock_trading.h"
22

33
#include <benchmark/benchmark.h>
44

@@ -7,7 +7,7 @@ static void BM_BuyAndSellStockOnceBruteForce(benchmark::State& state)
77
const auto prices = std::vector<int>{310, 315, 275, 295, 260, 270, 290, 230, 255, 250};
88
for (auto _ : state)
99
{
10-
TradeStock::BuyAndSellStockOnceBruteForce(prices);
10+
StockTrading::BuyAndSellStockOnceBruteForce(prices);
1111
}
1212
}
1313

@@ -18,7 +18,7 @@ static void BM_BuyAndSellStockOnce(benchmark::State& state)
1818
const auto prices = std::vector<int>{310, 315, 275, 295, 260, 270, 290, 230, 255, 250};
1919
for (auto _ : state)
2020
{
21-
TradeStock::BuyAndSellStockOnce(prices);
21+
StockTrading::BuyAndSellStockOnce(prices);
2222
}
2323
}
2424

@@ -29,7 +29,7 @@ static void BM_BuyAndSellStockTwice(benchmark::State& state)
2929
const auto prices = std::vector<double>{12.0, 11.0, 13.0, 9.0, 12.0, 8.0, 14.0, 13.0, 15.0};
3030
for (auto _ : state)
3131
{
32-
TradeStock::BuyAndSellStockTwice(prices);
32+
StockTrading::BuyAndSellStockTwice(prices);
3333
}
3434
}
3535

cpp-algorithm/src/array/trade_stock.cpp renamed to cpp-algorithm/src/array/stock_trading.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
#include "trade_stock.h"
1+
#include "stock_trading.h"
22

33
#include <limits>
44

5-
auto TradeStock::BuyAndSellStockOnceBruteForce(const std::vector<int>& prices) -> double
5+
auto StockTrading::BuyAndSellStockOnceBruteForce(const std::vector<int>& prices) -> double
66
{
77
auto max_profit = 0.0;
88

@@ -20,7 +20,7 @@ auto TradeStock::BuyAndSellStockOnceBruteForce(const std::vector<int>& prices) -
2020
return max_profit;
2121
}
2222

23-
auto TradeStock::BuyAndSellStockOnce(const std::vector<int>& prices) -> double
23+
auto StockTrading::BuyAndSellStockOnce(const std::vector<int>& prices) -> double
2424
{
2525
auto min_price_so_far = std::numeric_limits<double>::infinity();
2626
auto max_profit = 0.0;
@@ -35,7 +35,7 @@ auto TradeStock::BuyAndSellStockOnce(const std::vector<int>& prices) -> double
3535
return max_profit;
3636
}
3737

38-
auto TradeStock::BuyAndSellStockTwice(const std::vector<double>& prices) -> double
38+
auto StockTrading::BuyAndSellStockTwice(const std::vector<double>& prices) -> double
3939
{
4040
double max_total_profit = 0;
4141
std::vector<double> first_buy_sell_profits(prices.size(), 0);
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#ifndef CPP_ALGORITHM_STOCK_TRADING_H
2+
#define CPP_ALGORITHM_STOCK_TRADING_H
3+
4+
#include <vector>
5+
6+
namespace StockTrading
7+
{
8+
/**
9+
* \brief Buy and sell stock once. This is brute force.
10+
* \param prices prices of stock
11+
* \return best profit
12+
*/
13+
auto BuyAndSellStockOnceBruteForce(const std::vector<int>& prices) -> double;
14+
15+
/**
16+
* \brief Buy and sell stock once.
17+
* \param prices prices of stock
18+
* \return best profit
19+
*/
20+
auto BuyAndSellStockOnce(const std::vector<int>& prices) -> double;
21+
22+
/**
23+
* \brief Buy and sell stock twice.
24+
* \param prices prices of stock
25+
* \return best profit
26+
*/
27+
auto BuyAndSellStockTwice(const std::vector<double>& prices) -> double;
28+
}
29+
30+
#endif

cpp-algorithm/src/array/test/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,4 @@ add_target_test(enumerate_prime_number_test)
3838
# add_target_test(order_element_test)
3939
add_target_test(random_data_sampling_test)
4040
add_target_test(replace_element_test)
41-
add_target_test(trade_stock_test)
41+
add_target_test(stock_trading_test)
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,27 @@
1-
#include "trade_stock.h"
1+
#include "stock_trading.h"
22

33
#include <gtest/gtest.h>
44

5-
GTEST_TEST(TradeStock, BuyAndSellStockOnceBruteForce)
5+
GTEST_TEST(StockTrading, BuyAndSellStockOnceBruteForce)
66
{
77
const auto prices = std::vector<int>{310, 315, 275, 295, 260, 270, 290, 230, 255, 250};
88
constexpr auto expected = 30;
9-
const auto result = TradeStock::BuyAndSellStockOnceBruteForce(prices);
9+
const auto result = StockTrading::BuyAndSellStockOnceBruteForce(prices);
1010
EXPECT_EQ(expected, result);
1111
}
1212

13-
GTEST_TEST(TradeStock, BuyAndSellStockOnce)
13+
GTEST_TEST(StockTrading, BuyAndSellStockOnce)
1414
{
1515
const auto prices = std::vector<int>{310, 315, 275, 295, 260, 270, 290, 230, 255, 250};
1616
constexpr auto expected = 30;
17-
const auto result = TradeStock::BuyAndSellStockOnce(prices);
17+
const auto result = StockTrading::BuyAndSellStockOnce(prices);
1818
EXPECT_EQ(expected, result);
1919
}
2020

21-
GTEST_TEST(TradeStock, BuyAndSellStockTwice)
21+
GTEST_TEST(StockTrading, BuyAndSellStockTwice)
2222
{
2323
const auto prices = std::vector<double>{12.0, 11.0, 13.0, 9.0, 12.0, 8.0, 14.0, 13.0, 15.0};
2424
constexpr auto expected = 10.0;
25-
const auto result = TradeStock::BuyAndSellStockTwice(prices);
25+
const auto result = StockTrading::BuyAndSellStockTwice(prices);
2626
EXPECT_EQ(expected, result);
2727
}

cpp-algorithm/src/array/trade_stock.h

Lines changed: 0 additions & 24 deletions
This file was deleted.

0 commit comments

Comments
 (0)