-
Notifications
You must be signed in to change notification settings - Fork 1
/
sorting_test.go
47 lines (44 loc) · 5.02 KB
/
sorting_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
package data_structure_go
import (
"fmt"
"testing"
"time"
)
func TestSortingAlgorithm_BubbleSort(t *testing.T) {
timeStart := time.Now()
array := []int{2494, 1853, 524, 2068, 1750, 208, 950, 1609, 1672, 128, 1166, 1390, 750, 1073, 2735, 2545, 2291, 227, 1919, 2560, 906, 2937, 2838, 881, 495, 220, 562, 2880, 973, 1364, 2088, 1902, 535, 2522, 2925, 2660, 2378, 2549, 2266, 2644, 711, 1183, 934, 2368, 959, 2819, 2509, 2442, 750, 2653, 1350, 2127, 1634, 630, 459, 2073, 293, 2898, 217, 39, 2774, 80, 2055, 2043, 751, 2565, 2508, 1584, 2495, 365, 2593, 101, 1343, 2008, 429, 2635, 2305, 1213, 207, 2151, 20, 494, 470, 2180, 2388, 1471, 149, 2200, 1039, 1116, 1850, 2681, 426, 2126, 1629, 204, 586, 57, 2862, 818, 1271, 1589, 2359, 792, 2955, 1543, 2369, 177, 2080, 364, 2010, 1754, 2742, 1025, 2203, 417, 1180, 1082, 2864, 635, 2654, 861, 913, 1273, 1661, 1146, 1846, 1350, 2333, 2898, 1623, 840, 1040, 2064, 1937, 2232, 943, 264, 1436, 672, 2816, 683, 209, 2224, 851, 1164, 1313, 1268, 1870, 1602, 913, 2582, 2905, 2051, 2610, 843, 988, 2361, 2540, 1445, 1700, 2107, 1298, 2741, 1956, 979, 1649, 2450, 1768, 2479, 2891, 2810, 2413, 726, 2808, 1764, 1580, 545, 844, 1248, 1718, 1492, 2483, 1140, 1194, 2952, 1144, 939, 313, 1710, 1421, 276, 1714, 730, 2245, 1741, 1897, 2497, 2853, 2161, 2490, 864, 2210, 2245, 2435, 2402, 2468, 2411, 2664, 1662, 1623, 2849, 2616, 219, 1194, 2834, 1013, 2297, 2488, 1190, 1425, 1982, 156, 984, 435, 1129, 1986, 156, 2833, 2358, 9, 1819, 2232, 430, 2324, 2844, 1750, 2059, 543, 49, 2481, 1469, 487, 331, 2064, 164, 2738, 1499, 1159, 146, 2622, 1367, 840, 1324, 1246, 1212, 116, 1485, 2966, 462, 218, 199, 991, 2321, 1422, 567, 2838, 2451, 2339, 291, 2063, 401, 163, 1995, 1272, 931, 234, 2578, 1672, 764, 227, 1735, 646, 1641, 1138, 388, 77, 2910, 945, 258, 181, 167, 1422, 2839, 117, 954, 1186, 2382, 1436, 1495, 2204, 1873, 2096, 1144, 1363, 2884, 2934, 1195, 1426, 2537, 1887, 2705, 1710, 1188, 883, 882, 500, 1971, 1303, 695, 2461, 1572, 1426, 1188, 2131, 2827, 2334, 872, 1821, 950, 82, 1082, 2750, 2806, 404, 1050, 2140, 420, 2212, 2457, 557, 6, 811, 630, 76, 693, 2394, 1309, 320, 2820, 1992, 1398, 1205, 2439, 1467, 2328}
sorting := NewSortingAlgorithm(&array)
sorting.BubbleSortDescending()
sorting.PrintArray()
sorting.BubbleSortAscending()
sorting.PrintArray()
elapsed := time.Since(timeStart)
fmt.Println("Waktu eksekusi : ", elapsed)
/*
=== RUN TestSortingAlgorithm_BubbleSort
93, 56, 45, 34, 34, 24, 21, 20, 4, 1,
1, 4, 20, 21, 24, 34, 34, 45, 56, 93,
--- PASS: TestBubbleSort (0.00s)
PASS
Process finished with the exit code 0
*/
}
func TestSortingAlgorithm_QuickSort(t *testing.T) {
timeStart := time.Now()
array := []int{2494, 1853, 524, 2068, 1750, 208, 950, 1609, 1672, 128, 1166, 1390, 750, 1073, 2735, 2545, 2291, 227, 1919, 2560, 906, 2937, 2838, 881, 495, 220, 562, 2880, 973, 1364, 2088, 1902, 535, 2522, 2925, 2660, 2378, 2549, 2266, 2644, 711, 1183, 934, 2368, 959, 2819, 2509, 2442, 750, 2653, 1350, 2127, 1634, 630, 459, 2073, 293, 2898, 217, 39, 2774, 80, 2055, 2043, 751, 2565, 2508, 1584, 2495, 365, 2593, 101, 1343, 2008, 429, 2635, 2305, 1213, 207, 2151, 20, 494, 470, 2180, 2388, 1471, 149, 2200, 1039, 1116, 1850, 2681, 426, 2126, 1629, 204, 586, 57, 2862, 818, 1271, 1589, 2359, 792, 2955, 1543, 2369, 177, 2080, 364, 2010, 1754, 2742, 1025, 2203, 417, 1180, 1082, 2864, 635, 2654, 861, 913, 1273, 1661, 1146, 1846, 1350, 2333, 2898, 1623, 840, 1040, 2064, 1937, 2232, 943, 264, 1436, 672, 2816, 683, 209, 2224, 851, 1164, 1313, 1268, 1870, 1602, 913, 2582, 2905, 2051, 2610, 843, 988, 2361, 2540, 1445, 1700, 2107, 1298, 2741, 1956, 979, 1649, 2450, 1768, 2479, 2891, 2810, 2413, 726, 2808, 1764, 1580, 545, 844, 1248, 1718, 1492, 2483, 1140, 1194, 2952, 1144, 939, 313, 1710, 1421, 276, 1714, 730, 2245, 1741, 1897, 2497, 2853, 2161, 2490, 864, 2210, 2245, 2435, 2402, 2468, 2411, 2664, 1662, 1623, 2849, 2616, 219, 1194, 2834, 1013, 2297, 2488, 1190, 1425, 1982, 156, 984, 435, 1129, 1986, 156, 2833, 2358, 9, 1819, 2232, 430, 2324, 2844, 1750, 2059, 543, 49, 2481, 1469, 487, 331, 2064, 164, 2738, 1499, 1159, 146, 2622, 1367, 840, 1324, 1246, 1212, 116, 1485, 2966, 462, 218, 199, 991, 2321, 1422, 567, 2838, 2451, 2339, 291, 2063, 401, 163, 1995, 1272, 931, 234, 2578, 1672, 764, 227, 1735, 646, 1641, 1138, 388, 77, 2910, 945, 258, 181, 167, 1422, 2839, 117, 954, 1186, 2382, 1436, 1495, 2204, 1873, 2096, 1144, 1363, 2884, 2934, 1195, 1426, 2537, 1887, 2705, 1710, 1188, 883, 882, 500, 1971, 1303, 695, 2461, 1572, 1426, 1188, 2131, 2827, 2334, 872, 1821, 950, 82, 1082, 2750, 2806, 404, 1050, 2140, 420, 2212, 2457, 557, 6, 811, 630, 76, 693, 2394, 1309, 320, 2820, 1992, 1398, 1205, 2439, 1467, 2328}
sorting := NewSortingAlgorithm(&array)
sorting.PrintArray()
sorting.QuickSortAscending()
sorting.PrintArray()
sorting.QuickSortDescending()
sorting.PrintArray()
elapsed := time.Since(timeStart)
fmt.Println("Waktu eksekusi : ", elapsed)
/*S
=== RUN TestSortingAlgorithm_QuickSort
1, 4, 20, 21, 24, 34, 34, 45, 56, 93,
--- PASS: TestSortingAlgorithm_QuickSort (0.00s)
PASS
Process finished with the exit code 0
*/
}