-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.ahk
69 lines (49 loc) · 2.49 KB
/
examples.ahk
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
#SingleInstance, Force
; #Warn ; Enable warnings to assist with detecting common errors.
SendMode Input
SetWorkingDir, %A_ScriptDir%
;creating a shortener using standard one sign symbols
shortenerExample1 := new IntShortening(2, "k", "M", "B")
example(shortenerExample1, "shortenerExample1")
;creating a shortener using standard one sign symbols for amounts of data
shortenerExample2 := new IntShortening(2, "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
shortenerExample2.0 := "B"
example(shortenerExample2, "shortenerExample2")
;the shortening class could use any string for the ending
shortenerExample3 := new IntShortening(1, " thousand", " million", " billion")
example(shortenerExample3, "shortenerExample3")
;for numbers larger than 2147483647 (maximum integer size), pass them as strings
shortenerExample4 := new IntShortening(2, "kB", "MB", "GB", "TB", "PB", "EB", "ZB", "YB")
MsgBox, % """12345678901234567890"" shortened: " . shortenerExample2.stdFloor("12345678901234567890")
return
/*
test for various legal ints to show the posibilitys of this lib
*/
example(obj, exampleText){
static testsnumbers := [0, 5, 27, 924, 1355, 12345]
test := exampleText . "`nstatic numbers for testing:`n"
for k, element in testsnumbers{
test .= Format("`nMethod: {1:s}, Accuracy: {2:d}, Input: {3:d}, Out: {4:s}", "stdFloor(int)", obj.accuracy, element, obj.stdFloor(element))
test .= Format("`nMethod: {1:s}, Accuracy: {2:d}, Input: {3:d}, Out: {4:s}", "stdRound(int)", obj.accuracy, element, obj.stdRound(element))
}
MsgBox, , % "IntShortener Class Test", % test
MsgBox, , % "IntShortener Class Test Test", % DynExample(obj, 0, 999, exampleText)
MsgBox, , % "IntShortener Class Test Test", % DynExample(obj, 1000, 999999, exampleText)
MsgBox, , % "IntShortener Class Test Test", % DynExample(obj, 1000000, 999999999, exampleText)
MsgBox, , % "IntShortener Class Test Test", % DynExample(obj, 1000000000, 2147483647, exampleText)
}
/*
creates dynamically generated integers for random tests
*/
DynExample(obj, min, max, exampleText){
test := exampleText . "`nTestrange: " . min . " <= x < " . max + 1 . "`n"
if(max > 2147483647)
correction := max - 2147483647
Loop, 5 {
Random, num, min, max
test .= Format("`nMethod: {1:s}, Accuracy: {2:d}, Input: {3:s}, Out: {4:s}", "stdFloor(int)", obj.accuracy, num, obj.stdFloor(num))
test .= Format("`nMethod: {1:s}, Accuracy: {2:d}, Input: {3:s}, Out: {4:s}", "stdRound(int)", obj.accuracy, num, obj.stdRound(num))
}
return, test
}
#Include, IntShortening.ahk