-
Notifications
You must be signed in to change notification settings - Fork 0
/
SerieProdottoTest.cs
97 lines (81 loc) · 2.68 KB
/
SerieProdottoTest.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// This file was auto-generated based on version 1.2.0 of the canonical data.
using System;
using Xunit;
public class LargestSeriesProductTest
{
[Fact]
public void Finds_the_largest_product_if_span_equals_length()
{
Assert.Equal(18, LargestSeriesProduct.GetLargestProduct("29", 2));
}
[Fact]
public void Can_find_the_largest_product_of_2_with_numbers_in_order()
{
Assert.Equal(72, LargestSeriesProduct.GetLargestProduct("0123456789", 2));
}
[Fact]
public void Can_find_the_largest_product_of_2()
{
Assert.Equal(48, LargestSeriesProduct.GetLargestProduct("576802143", 2));
}
[Fact]
public void Can_find_the_largest_product_of_3_with_numbers_in_order()
{
Assert.Equal(504, LargestSeriesProduct.GetLargestProduct("0123456789", 3));
}
[Fact]
public void Can_find_the_largest_product_of_3()
{
Assert.Equal(270, LargestSeriesProduct.GetLargestProduct("1027839564", 3));
}
[Fact]
public void Can_find_the_largest_product_of_5_with_numbers_in_order()
{
Assert.Equal(15120, LargestSeriesProduct.GetLargestProduct("0123456789", 5));
}
[Fact]
public void Can_get_the_largest_product_of_a_big_number()
{
Assert.Equal(23520, LargestSeriesProduct.GetLargestProduct("73167176531330624919225119674426574742355349194934", 6));
}
[Fact]
public void Reports_zero_if_the_only_digits_are_zero()
{
Assert.Equal(0, LargestSeriesProduct.GetLargestProduct("0000", 2));
}
[Fact]
public void Reports_zero_if_all_spans_include_zero()
{
Assert.Equal(0, LargestSeriesProduct.GetLargestProduct("99099", 3));
}
[Fact]
public void Rejects_span_longer_than_string_length()
{
Assert.Throws<ArgumentException>(() => LargestSeriesProduct.GetLargestProduct("123", 4));
}
[Fact]
public void Reports_1_for_empty_string_and_empty_product_0_span_()
{
Assert.Equal(1, LargestSeriesProduct.GetLargestProduct("", 0));
}
[Fact]
public void Reports_1_for_nonempty_string_and_empty_product_0_span_()
{
Assert.Equal(1, LargestSeriesProduct.GetLargestProduct("123", 0));
}
[Fact]
public void Rejects_empty_string_and_nonzero_span()
{
Assert.Throws<ArgumentException>(() => LargestSeriesProduct.GetLargestProduct("", 1));
}
[Fact]
public void Rejects_invalid_character_in_digits()
{
Assert.Throws<ArgumentException>(() => LargestSeriesProduct.GetLargestProduct("1234a5", 2));
}
[Fact]
public void Rejects_negative_span()
{
Assert.Throws<ArgumentException>(() => LargestSeriesProduct.GetLargestProduct("12345", -1));
}
}