/
sunset_test.go
56 lines (51 loc) · 6.07 KB
/
sunset_test.go
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
// Copyright (c) 2019 Matúš Mrekaj.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License
package stacksandqueues
import (
"reflect"
"testing"
)
func TestSunsetView(t *testing.T) {
tests := []struct {
input []int
want []int
}{
{input: []int{6, 3, 4}, want: []int{2, 0}},
{input: []int{6, 9, 3, 9, 5, 16, 9, 13}, want: []int{7, 5}},
{input: []int{404, 208, 5, 5, 359, 330, 118, 394, 102, 260, 21, 396, 74, 350, 384, 18, 201, 224, 271, 260, 222, 26, 352, 193, 233, 419, 271, 414, 415, 157, 92, 255, 221, 17, 228, 133, 165, 396, 322, 195, 95, 305, 415, 71, 190, 48, 235, 248, 371, 116, 108, 293, 412, 109, 243, 50, 61, 66, 160, 379, 79, 385, 257, 407, 359, 310, 422, 394, 21, 429, 183, 366, 198, 125, 435, 176, 438, 337, 91, 1, 269, 250, 343, 373, 407, 331, 198, 99, 335, 239, 235, 148, 186, 382, 191, 289, 266, 61, 19, 280, 91, 225, 230, 22, 105, 213, 50, 46, 252, 415, 364, 90, 321, 153, 291, 172, 347, 412, 247, 363, 42, 444, 190, 430, 374, 434, 361, 340, 107, 122, 207, 114, 133, 49, 407, 410, 294, 313, 409, 67, 61, 27, 75, 50, 189, 2, 103, 420, 55, 431, 83, 438, 223, 277, 381, 366, 372, 389, 179, 334, 100, 402, 428, 18, 221, 253, 140, 271, 391, 430, 377, 386, 154, 196, 421, 183, 368, 148, 321, 181, 340, 207, 361, 206, 155, 14, 239, 81, 153, 111, 223, 157, 442, 91, 393, 57, 407, 151, 294, 271, 376, 322, 425, 233, 51, 99, 242, 76, 198, 54, 104, 1, 112, 1, 36, 312, 390, 67, 241, 269, 358, 111}, want: []int{221, 220, 216, 202, 192, 121}},
{input: []int{17, 15, 3, 15, 32, 14, 21, 26, 8, 34, 42, 14, 5, 4, 13, 42, 19, 36, 30, 14, 45, 20, 43, 13}, want: []int{23, 22, 20}},
{input: []int{1}, want: []int{0}},
{input: []int{700, 231, 836, 340, 71, 24, 553, 645, 212, 511, 98, 859, 101, 917, 210, 91, 302, 654, 412, 518, 771, 101, 718, 268, 602, 929, 323, 517, 227, 954, 98, 542, 916, 795, 282, 71, 257, 674, 502, 196, 660, 689, 569, 23, 352, 270, 798, 132, 305, 485, 636, 743, 756, 156, 615, 519, 693, 804, 832, 450, 635, 290, 73, 486, 166, 935, 914, 182, 418, 270, 874, 269, 806, 701, 885, 128, 646, 474, 231, 665, 869, 633, 725, 806, 351, 46, 193, 757, 669, 98, 836, 833, 806, 609, 21, 294, 212, 281, 225, 903, 67, 378, 748, 356, 515, 257, 95, 162, 817, 718, 305, 9, 619, 575, 870, 502, 928, 112, 21, 833, 370, 666, 59, 235, 54, 893, 114, 412, 192, 361, 336, 310, 956, 718, 593, 536, 592, 89, 769, 483, 46, 75, 528, 606, 277, 267, 87, 896, 155, 345, 153, 848, 814, 103, 962, 108, 355, 228, 292, 352, 694, 44, 879, 86, 169, 713, 324, 332, 178, 75, 89, 908, 499, 602, 657, 100, 7, 75, 651, 758, 345, 283, 644, 187, 164, 889, 31, 560, 804, 689, 523, 184, 513, 706, 561, 570, 49, 49, 205, 424, 1, 8, 817, 346, 35, 175, 17, 280, 292, 37, 79, 372, 393, 667, 571, 531, 476, 151, 166, 644, 488, 643, 713, 589, 278, 448, 543, 840, 925, 68, 68, 325, 117, 889, 788, 382, 805, 10, 193, 358, 872, 363, 170, 741, 511, 493, 246, 794, 542, 904, 232, 774, 766, 367, 323, 251, 337, 299, 504, 309, 680, 774, 960, 8, 490, 272, 739, 169, 770, 282, 767, 908, 113, 889, 110, 115, 628, 217, 172, 867, 269, 757, 444, 733, 851, 839, 305, 542, 465, 814, 823, 331, 592, 294, 18, 518, 332, 625, 709, 84, 133, 587, 947, 81, 44, 298, 791, 163, 625, 560, 449, 741, 461, 336, 532, 16, 319, 246, 874, 595, 209, 285, 540, 769, 466, 287, 933, 81, 62, 562, 744, 400, 311, 553, 822, 335, 699, 804, 578, 542, 929, 770, 663, 585, 500, 37, 472, 164, 164, 554, 901, 691, 3, 772, 62, 127, 711, 329, 721, 883, 854, 267, 473, 185, 272, 597, 946, 104, 51, 589, 307, 855, 148, 752, 392, 1, 852, 944, 903, 610, 427, 244, 246, 825, 511, 574, 769, 434, 377, 404, 945, 385, 948, 897, 35, 770, 150, 575, 173, 619, 943, 13, 693, 327, 166, 904, 415, 76, 438, 317, 25, 796, 37, 572, 609, 590, 302, 488, 641, 727, 64, 253, 820, 140, 742, 841, 420, 421, 225, 303, 322, 354, 660, 803, 557, 724, 686, 541, 87, 62, 113, 704, 481, 739, 205, 655, 910, 942, 261, 317, 362, 512, 260, 801, 582, 731, 617, 737, 726, 457, 309, 43, 231, 538, 93, 652, 322, 477, 794, 927, 592, 453, 626, 786, 247, 850, 475, 791, 5, 737, 119, 869, 565}, want: []int{482, 481, 469, 447, 400, 392, 262, 154}},
{input: []int{92, 106, 53, 33, 95, 147, 4, 111, 164, 53, 83, 150, 148, 189, 109, 130, 68, 42, 73, 161, 136, 56, 111, 96, 184, 96, 59, 134, 6, 147, 149, 28, 195, 132, 93, 117, 144, 87, 7, 127, 139, 102, 137, 128, 26, 21, 9, 148, 142, 168, 170, 45, 167, 24, 85, 86, 146, 38, 76, 109, 146, 8, 145, 168, 165, 203, 45, 11, 69, 51, 13, 91, 138, 106, 73, 71, 110, 44, 60, 89, 41, 180, 45, 53, 12, 171, 114, 44, 26, 146, 119, 62, 192, 105, 138, 119, 93, 102, 26, 161, 145, 161}, want: []int{101, 92, 65}},
{input: []int{10, 10, 5, 9, 8, 1}, want: []int{5, 4, 3, 1}},
{input: []int{34, 23, 14, 15, 18, 12, 33, 12, 15, 11, 21, 35, 36, 21, 19, 15, 31, 14}, want: []int{17, 16, 12}},
{input: []int{1, 10, 6, 9, 3}, want: []int{4, 3, 1}},
{input: []int{3, 7, 4, 7}, want: []int{3}},
{input: []int{}, want: []int{}},
{input: []int{9, 44, 34, 8, 14, 14, 32, 40, 6, 40, 35, 16, 20, 37, 42, 43, 23, 14, 41, 3, 9, 37}, want: []int{21, 18, 15, 1}},
{input: []int{16, 1, 12, 16, 4, 5, 7, 8, 16, 2}, want: []int{9, 8}},
{input: []int{4, 1}, want: []int{1, 0}},
{input: []int{13, 1, 27, 10, 8, 6, 15, 21, 23, 16, 21, 16, 2, 9}, want: []int{13, 11, 10, 8, 2}},
{input: []int{5, 3, 8, 3}, want: []int{3, 2}},
{input: []int{28, 15, 46, 44, 62, 30, 29, 36, 4, 8, 1, 52, 22, 31, 46, 26, 10, 31, 52, 40, 62, 1, 68, 6, 17, 30, 13, 48, 26, 53, 32, 57, 41, 19, 63}, want: []int{34, 22}},
{input: []int{3, 5, 2}, want: []int{2, 1}},
{input: []int{1, 5, 7, 7}, want: []int{3}},
}
for _, test := range tests {
got := ComputeSunsetView(test.input)
if !reflect.DeepEqual(got, test.want) {
t.Errorf("result mismatch. got: %v; want: %v", got, test.want)
}
}
}