public static void Test(){ int[] a = {7,9, 11, 6}; int[] b = {4,5, 1, 4}; MaxProfit p = new MaxProfit(); var res = p.Max(a,b); Console.WriteLine(res); }
public override int GetHashCode() { unchecked { return(base.GetHashCode() + MaxProfit.GetHashCode() + MinProfit.GetHashCode()); } }
public void test_methodName_withCertainState_shouldDoSomething(int[] given, int expected) { var target = new MaxProfit(); var actual = target.solution(given); Assert.AreEqual(expected, actual); }
public void ShoulCalculateMaxProfit(int[] A, int expected) { MaxProfit calculator = new MaxProfit(); int actual = calculator.Calculate(A); Assert.AreEqual(expected, actual); }
public void Max_Profit_Should_Handle_Complex_Profit_Scenario() { MaxProfit subject = new MaxProfit(); int[] array = { 100, 200, 800, 600, 400, 1600, 950, 0, 1500, 2000 }; Assert.Equal(2000, subject.solution(array)); }
public void Max_Profit_Should_Handle_Simple_Profit_Scenario() { MaxProfit subject = new MaxProfit(); int[] array = { 100, 200, 800, 600 }; Assert.Equal(700, subject.solution(array)); }
public void Max_Profit_Should_Handle_Negative_Values_And_No_Profits() { MaxProfit subject = new MaxProfit(); int[] array = { 5000, 0, 0, 0 }; Assert.Equal(0, subject.solution(array)); }
public void Max_Profit_Should_Identify_No_Profits() { MaxProfit subject = new MaxProfit(); int[] array = { 0, 0, 0, 0 }; Assert.Equal(0, subject.solution(array)); }
public void Max_Profit_Should_Handle_Empty_Array() { MaxProfit subject = new MaxProfit(); int[] array = { }; Assert.Equal(0, subject.solution(array)); }
public void Excution1Test() { var func = new MaxProfit(); Assert.AreEqual(5, func.Excution1(new[] { 7, 1, 5, 3, 6, 4 })); Assert.AreEqual(0, func.Excution1(new[] { 7, 6, 4, 3, 1 })); Assert.AreEqual(0, func.Excution1(new[] { 1 })); }
private static void TestMaxProfit() { MaxProfit instance = new MaxProfit(); Console.WriteLine(instance.Solution(new[] { 3, 2, 6, 5, 0, 3 })); Console.WriteLine(instance.Solution(new[] { 1, 2, 3, 0, 2 })); //3 }
public void Max_Profit_Should_Handle_Max_Values() { MaxProfit subject = new MaxProfit(); int[] array = { 0, 0, 0, 0, 200000 }; Assert.Equal(200000, subject.solution(array)); }
public void WhenSendindDefaultArrayShouldReturn356() { var expectedValue = 356; var maxProfit = new MaxProfit(); var baseCaseArray = new int[] { 23171, 21011, 21123, 21366, 21013, 21367 }; var actualValue = maxProfit.Solution(baseCaseArray); Assert.AreEqual(expectedValue, actualValue); }
public void WhenAfterMaxAndBeforeMinMaxProfitShouldReturnRightValue() { var expectedValue = 7; var maxProfit = new MaxProfit(); var baseCaseArray = new int[] { 30, 1, 6, 7, 8, 0 }; var actualValue = maxProfit.Solution(baseCaseArray); Assert.AreEqual(expectedValue, actualValue); }
public void WhenSendindTwoIncreasingSubsequencesShouldReturnRightValue() { var expectedValue = 9; var maxProfit = new MaxProfit(); var baseCaseArray = new int[] { 0, 1, 6, 7, 8, 9 }; var actualValue = maxProfit.Solution(baseCaseArray); Assert.AreEqual(expectedValue, actualValue); }
public List <string> GetTableRow() { return(new List <string> { GoodCount.ToString(), BadCount.ToString(), Profit.ToString(), Volume.ToString(), (100 * Math.Round(Profit / (double)Volume, 3)).ToEnString(), MaxLoss.ToString(), MaxProfit.ToString(), Math.Round(MaxDropdown, 2).ToEnString(), MaxDropdownLength.ToString(), Math.Round(ProfitAverage, 2).ToEnString(), Math.Round(LossAverage, 2).ToEnString(), LongGoodCount.ToString(), ShortGoodCount.ToString() }); }
public void GetMaxProfit_Sample_356() { var prices = new int[] { 23171, 21011, 21123, 21366, 21013, 21367 }; var solver = new MaxProfit(); var maxProfit = solver.GetMaxProfit(prices); maxProfit.Should().Be(356); }
public void maxProfitTest() { foreach (MaxProfitTestData testData in TestDataList) { Console.WriteLine("Test iutput: " + string.Join(",", testData.InputArray)); Assert.AreEqual(testData.OutputInt, MaxProfit.maxProfit(testData.InputArray)); Assert.AreEqual(testData.OutputInt, MaxProfit.maxProfitG(testData.InputArray)); Assert.AreEqual(testData.OutputInt, MaxProfit.maxProfitGG(testData.InputArray)); } }
/// <summary> /// Find max profit date for each ticker when bought at the lowest and sold at the highest price of the day /// </summary> /// <param name="tickerData">Daily Data grouped by its ticker</param> /// <returns>Max profit date data for each ticker</returns> public static string CalculateHighestProfitDay(IDictionary <string, IList <DailySummary> > tickerData) { var maxProfitData = new Dictionary <string, MaxProfit>(); foreach (KeyValuePair <string, IList <DailySummary> > dailyData in tickerData) { foreach (var data in dailyData.Value) { string ticker = data.Ticker; DateTime date = data.Date; decimal dailyHigh = data.High; decimal dailyLow = data.Low; decimal dailyProfit = decimal.Round(dailyHigh - dailyLow, 2); if (maxProfitData.ContainsKey(ticker)) { if (dailyProfit > maxProfitData[ticker].max_profit) { maxProfitData[ticker].max_profit = dailyProfit; maxProfitData[ticker].Date = date.ToString("yyyy-MM-dd"); maxProfitData[ticker].low = dailyLow; maxProfitData[ticker].high = dailyHigh; } } else { maxProfitData[ticker] = new MaxProfit { Date = data.Date.ToString("yyyy-MM-dd"), low = data.Low, high = data.High, max_profit = dailyProfit }; } } } //Return Readable/formatted max profit result return(JsonConvert.SerializeObject(maxProfitData, Formatting.Indented)); }
public void Initialize() { _maxProfit = new MaxProfit(); }
public static void callMaxProfit() { MaxProfit prb = new MaxProfit(); Console.WriteLine(prb.GetMaxProfit(new int[] { 7, 6, 4, 3, 1 })); }