How to use ok method in Puppeteer

Best JavaScript code snippet using puppeteer

Run Puppeteer automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

check_dep.py

Source: check_dep.py Github

copy
1#Bruno Iochins Grisci and Marcelo D. Poleto
2#APRIL/2019
3#http://sbcb.inf.ufrgs.br/confid
4# -*- coding:utf-8 -*-
5
6def check(print_ok=False):
7
8    if print_ok:
9        print('Checking for needed packages and libs...')
10
11    try:
12        import os
13        if print_ok:
14            print('OK: os')
15    except:
16        print('ERROR: could not import os')
17    try:
18        import sys
19        if print_ok:
20            print('OK: sys')
21    except:
22        print('ERROR: could not import sys')
23    try:
24        import shutil
25        if print_ok:
26            print('OK: shutil')
27    except:
28        print('ERROR: could not import shutil')        
29    try:
30        import pprint
31        if print_ok:
32            print('OK: pprint')
33    except:
34        print('ERROR: could not import pprint')
35    try:
36        import re
37        if print_ok:
38            print('OK: re')
39    except:
40        print('ERROR: could not import re')
41    try:
42        import numpy as np
43        if print_ok:
44            print('OK: numpy')
45    except:
46        print('ERROR: could not import numpy')
47    try:
48        import operator
49        if print_ok:
50            print('OK: operator')
51    except:
52        print('ERROR: could not import operator')
53    try:
54        from collections import Counter
55        if print_ok:
56            print('OK: Counter from collections')
57    except:
58        print('ERROR: could not import Counter from collections')
59    try:
60        import timeit
61        if print_ok:
62            print('OK: timeit')
63    except:
64        print('ERROR: could not import timeit')  
65    if not (sys.version_info >= (3, 0)):
66        try:
67            from itertools import imap
68            if print_ok:
69                print('OK: imap from itertools')
70        except:
71            print('WARNING: could not import imap from itertools, if using Python 3.x ignore this warning')
72
73    if print_ok:
74        print('Checking for optional packages and libs...')
75
76    try:
77        import graphviz
78        if print_ok:
79            print('OK: graphviz')
80    except:
81        print('WARNING: could not import graphviz')
82        print('WARNING: graphviz is needed if PLOT_GRAPH is True.')
83    try:
84        import pydot
85        if print_ok:
86            print('OK: pydot')
87    except:
88        pass       
89    try:
90        import matplotlib.pyplot as plt
91        if print_ok:
92            print('OK: matplotlib.pyplot')
93    except:
94        print('WARNING: could not import matplotlib.pyplot')
95        print('WARNING: matplotlib.pyplot is needed if TIME_DEPENDENT_STATS is True.')
96    if print_ok:
97        print('Finished.')
98
99if __name__ == '__main__':
100    check(print_ok=True)
Full Screen

split.py

Source: split.py Github

copy
1import os
2import shutil
3
4folders = "E:/DATA/3_fold/"
5sub_folders = os.listdir(folders)
6ok = "E:/DATA/KolektorSDD_MOD/OK,negative/"
7ng = "E:/DATA/KolektorSDD_MOD/NG,positive/"
8images_ok = os.listdir(ok)
9images_ng = os.listdir(ng)
10
11for each_folder in sub_folders:
12	path_sub = os.path.join(folders, each_folder)
13	sub_files = os.listdir(path_sub)
14
15	train_folder = os.path.join(path_sub,"train_set")
16	test_folder = os.path.join(path_sub, "test_set")
17	sub_ok_folder = os.path.join(train_folder, "OK,negative")
18	sub_ng_folder = os.path.join(train_folder, "NG,positive")
19	if not os.path.exists(sub_ok_folder):
20		os.makedirs(sub_ok_folder)
21	if not os.path.exists(sub_ng_folder):
22		os.makedirs(sub_ng_folder)
23	if not os.path.exists(test_folder):
24		os.makedirs(test_folder)
25
26	for p in sub_files:
27		if p == "train_ids.txt":
28			train_set = []
29			p_path = os.path.join(path_sub, p)
30			f = open(p_path)
31			lines = f.readlines()
32			count = 0
33			for line in lines:
34				s = line.strip("\n").split("/")[-1]
35				train_set.append(s)
36			#print(train_set)
37			for each_image_ok in images_ok:
38				#print(each_image_ok)
39				this_ok_image_path = os.path.join(ok, each_image_ok)
40				print(this_ok_image_path)
41				pre_fix = each_image_ok.split("_")[0]
42				#print(pre_fix)
43				if pre_fix in train_set:
44					target_ok_path = os.path.join(sub_ok_folder, each_image_ok)
45					#print(target_path)
46					shutil.copy(this_ok_image_path, target_ok_path)
47
48			for each_image_ng in images_ng:
49				#print(each_image_ok)
50				this_ng_image_path = os.path.join(ng, each_image_ng)
51				#print(this_ng_image_path)
52				pre_fix = each_image_ng.split("_")[0]
53				#print(pre_fix)
54				if pre_fix in train_set:
55					target_ng_path = os.path.join(sub_ng_folder, each_image_ng)
56					#print(target_path)
57					shutil.copy(this_ng_image_path, target_ng_path)
58
59		if p == "test_ids.txt":
60			test_set = []
61			p_path = os.path.join(path_sub, p)
62			f = open(p_path)
63			lines = f.readlines()
64			count = 0
65			for line in lines:
66				s = line.strip("\n").split("/")[-1]
67				test_set.append(s)
68			#print(train_set)
69			for each_image_ok in images_ok:
70				#print(each_image_ok)
71				this_ok_image_path = os.path.join(ok, each_image_ok)
72				print(this_ok_image_path)
73				pre_fix = each_image_ok.split("_")[0]
74				#print(pre_fix)
75				if pre_fix in test_set:
76					target_ok_path = test_folder
77					#print(target_path)
78					shutil.copy(this_ok_image_path, target_ok_path)
79
80			for each_image_ng in images_ng:
81				#print(each_image_ok)
82				this_ng_image_path = os.path.join(ng, each_image_ng)
83				#print(this_ng_image_path)
84				pre_fix = each_image_ng.split("_")[0]
85				#print(pre_fix)
86				if pre_fix in test_set:
87					target_ng_path = test_folder
88					#print(target_path)
89					shutil.copy(this_ng_image_path, target_ng_path)
90
91
92
Full Screen

ldb_test.py

Source: ldb_test.py Github

copy
1import os
2import os.path
3import shutil
4import subprocess
5import time
6import unittest
7import tempfile
8
9def my_check_output(*popenargs, **kwargs):
10    """
11    If we had python 2.7, we should simply use subprocess.check_output.
12    This is a stop-gap solution for python 2.6
13    """
14    if 'stdout' in kwargs:
15        raise ValueError('stdout argument not allowed, it will be overridden.')
16    process = subprocess.Popen(stderr=subprocess.PIPE, stdout=subprocess.PIPE,
17                               *popenargs, **kwargs)
18    output, unused_err = process.communicate()
19    retcode = process.poll()
20    if retcode:
21        cmd = kwargs.get("args")
22        if cmd is None:
23            cmd = popenargs[0]
24        raise Exception("Exit code is not 0.  It is %d.  Command: %s" %
25                (retcode, cmd))
26    return output
27
28def run_err_null(cmd):
29    return os.system(cmd + " 2>/dev/null ")
30
31class LDBTestCase(unittest.TestCase):
32    def setUp(self):
33        self.TMP_DIR  = tempfile.mkdtemp(prefix="ldb_test_")
34        self.DB_NAME = "testdb"
35
36    def tearDown(self):
37        assert(self.TMP_DIR.strip() != "/"
38                and self.TMP_DIR.strip() != "/tmp"
39                and self.TMP_DIR.strip() != "/tmp/") #Just some paranoia
40
41        shutil.rmtree(self.TMP_DIR)
42
43    def dbParam(self, dbName):
44        return "--db=%s" % os.path.join(self.TMP_DIR, dbName)
45
46    def assertRunOKFull(self, params, expectedOutput, unexpected=False):
47        """
48        All command-line params must be specified.
49        Allows full flexibility in testing; for example: missing db param.
50
51        """
52
53        output = my_check_output("./ldb %s |grep -v \"Created bg thread\"" %
54                            params, shell=True)
55        if not unexpected:
56            self.assertEqual(output.strip(), expectedOutput.strip())
57        else:
58            self.assertNotEqual(output.strip(), expectedOutput.strip())
59
60    def assertRunFAILFull(self, params):
61        """
62        All command-line params must be specified.
63        Allows full flexibility in testing; for example: missing db param.
64
65        """
66        try:
67
68            my_check_output("./ldb %s >/dev/null 2>&1 |grep -v \"Created bg \
69                thread\"" % params, shell=True)
70        except Exception, e:
71            return
72        self.fail(
73            "Exception should have been raised for command with params: %s" %
74            params)
75
76    def assertRunOK(self, params, expectedOutput, unexpected=False):
77        """
78        Uses the default test db.
79
80        """
81        self.assertRunOKFull("%s %s" % (self.dbParam(self.DB_NAME), params),
82                             expectedOutput, unexpected)
83
84    def assertRunFAIL(self, params):
85        """
86        Uses the default test db.
87        """
88        self.assertRunFAILFull("%s %s" % (self.dbParam(self.DB_NAME), params))
89
90    def testSimpleStringPutGet(self):
91        print "Running testSimpleStringPutGet..."
92        self.assertRunFAIL("put x1 y1")
93        self.assertRunOK("put --create_if_missing x1 y1", "OK")
94        self.assertRunOK("get x1", "y1")
95        self.assertRunFAIL("get x2")
96
97        self.assertRunOK("put x2 y2", "OK")
98        self.assertRunOK("get x1", "y1")
99        self.assertRunOK("get x2", "y2")
100        self.assertRunFAIL("get x3")
101
102        self.assertRunOK("scan --from=x1 --to=z", "x1 : y1\nx2 : y2")
103        self.assertRunOK("put x3 y3", "OK")
104
105        self.assertRunOK("scan --from=x1 --to=z", "x1 : y1\nx2 : y2\nx3 : y3")
106        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3")
107        self.assertRunOK("scan --from=x", "x1 : y1\nx2 : y2\nx3 : y3")
108
109        self.assertRunOK("scan --to=x2", "x1 : y1")
110        self.assertRunOK("scan --from=x1 --to=z --max_keys=1", "x1 : y1")
111        self.assertRunOK("scan --from=x1 --to=z --max_keys=2",
112                "x1 : y1\nx2 : y2")
113
114        self.assertRunOK("scan --from=x1 --to=z --max_keys=3",
115                "x1 : y1\nx2 : y2\nx3 : y3")
116        self.assertRunOK("scan --from=x1 --to=z --max_keys=4",
117                "x1 : y1\nx2 : y2\nx3 : y3")
118        self.assertRunOK("scan --from=x1 --to=x2", "x1 : y1")
119        self.assertRunOK("scan --from=x2 --to=x4", "x2 : y2\nx3 : y3")
120        self.assertRunFAIL("scan --from=x4 --to=z") # No results => FAIL
121        self.assertRunFAIL("scan --from=x1 --to=z --max_keys=foo")
122
123        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3")
124
125        self.assertRunOK("delete x1", "OK")
126        self.assertRunOK("scan", "x2 : y2\nx3 : y3")
127
128        self.assertRunOK("delete NonExistentKey", "OK")
129        # It is weird that GET and SCAN raise exception for
130        # non-existent key, while delete does not
131
132        self.assertRunOK("checkconsistency", "OK")
133
134    def dumpDb(self, params, dumpFile):
135        return 0 == run_err_null("./ldb dump %s > %s" % (params, dumpFile))
136
137    def loadDb(self, params, dumpFile):
138        return 0 == run_err_null("cat %s | ./ldb load %s" % (dumpFile, params))
139
140    def testStringBatchPut(self):
141        print "Running testStringBatchPut..."
142        self.assertRunOK("batchput x1 y1 --create_if_missing", "OK")
143        self.assertRunOK("scan", "x1 : y1")
144        self.assertRunOK("batchput x2 y2 x3 y3 \"x4 abc\" \"y4 xyz\"", "OK")
145        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 abc : y4 xyz")
146        self.assertRunFAIL("batchput")
147        self.assertRunFAIL("batchput k1")
148        self.assertRunFAIL("batchput k1 v1 k2")
149
150    def testCountDelimDump(self):
151        print "Running testCountDelimDump..."
152        self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK")
153        self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK")
154        self.assertRunOK("dump --count_delim", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8")
155        self.assertRunOK("dump --count_delim=\".\"", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8")
156        self.assertRunOK("batchput x,2 x2 x,abc xabc", "OK")
157        self.assertRunOK("dump --count_delim=\",\"", "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8")
158
159    def testCountDelimIDump(self):
160        print "Running testCountDelimIDump..."
161        self.assertRunOK("batchput x.1 x1 --create_if_missing", "OK")
162        self.assertRunOK("batchput y.abc abc y.2 2 z.13c pqr", "OK")
163        self.assertRunOK("dump --count_delim", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8")
164        self.assertRunOK("dump --count_delim=\".\"", "x => count:1\tsize:5\ny => count:2\tsize:12\nz => count:1\tsize:8")
165        self.assertRunOK("batchput x,2 x2 x,abc xabc", "OK")
166        self.assertRunOK("dump --count_delim=\",\"", "x => count:2\tsize:14\nx.1 => count:1\tsize:5\ny.2 => count:1\tsize:4\ny.abc => count:1\tsize:8\nz.13c => count:1\tsize:8")
167
168    def testInvalidCmdLines(self):
169        print "Running testInvalidCmdLines..."
170        # db not specified
171        self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing")
172        # No param called he
173        self.assertRunFAIL("put 0x6133 0x6233 --he --create_if_missing")
174        # max_keys is not applicable for put
175        self.assertRunFAIL("put 0x6133 0x6233 --max_keys=1 --create_if_missing")
176        # hex has invalid boolean value
177
178    def testHexPutGet(self):
179        print "Running testHexPutGet..."
180        self.assertRunOK("put a1 b1 --create_if_missing", "OK")
181        self.assertRunOK("scan", "a1 : b1")
182        self.assertRunOK("scan --hex", "0x6131 : 0x6231")
183        self.assertRunFAIL("put --hex 6132 6232")
184        self.assertRunOK("put --hex 0x6132 0x6232", "OK")
185        self.assertRunOK("scan --hex", "0x6131 : 0x6231\n0x6132 : 0x6232")
186        self.assertRunOK("scan", "a1 : b1\na2 : b2")
187        self.assertRunOK("get a1", "b1")
188        self.assertRunOK("get --hex 0x6131", "0x6231")
189        self.assertRunOK("get a2", "b2")
190        self.assertRunOK("get --hex 0x6132", "0x6232")
191        self.assertRunOK("get --key_hex 0x6132", "b2")
192        self.assertRunOK("get --key_hex --value_hex 0x6132", "0x6232")
193        self.assertRunOK("get --value_hex a2", "0x6232")
194        self.assertRunOK("scan --key_hex --value_hex",
195                "0x6131 : 0x6231\n0x6132 : 0x6232")
196        self.assertRunOK("scan --hex --from=0x6131 --to=0x6133",
197                "0x6131 : 0x6231\n0x6132 : 0x6232")
198        self.assertRunOK("scan --hex --from=0x6131 --to=0x6132",
199                "0x6131 : 0x6231")
200        self.assertRunOK("scan --key_hex", "0x6131 : b1\n0x6132 : b2")
201        self.assertRunOK("scan --value_hex", "a1 : 0x6231\na2 : 0x6232")
202        self.assertRunOK("batchput --hex 0x6133 0x6233 0x6134 0x6234", "OK")
203        self.assertRunOK("scan", "a1 : b1\na2 : b2\na3 : b3\na4 : b4")
204        self.assertRunOK("delete --hex 0x6133", "OK")
205        self.assertRunOK("scan", "a1 : b1\na2 : b2\na4 : b4")
206        self.assertRunOK("checkconsistency", "OK")
207
208    def testTtlPutGet(self):
209        print "Running testTtlPutGet..."
210        self.assertRunOK("put a1 b1 --ttl --create_if_missing", "OK")
211        self.assertRunOK("scan --hex", "0x6131 : 0x6231", True)
212        self.assertRunOK("dump --ttl ", "a1 ==> b1", True)
213        self.assertRunOK("dump --hex --ttl ",
214                         "0x6131 ==> 0x6231\nKeys in range: 1")
215        self.assertRunOK("scan --hex --ttl", "0x6131 : 0x6231")
216        self.assertRunOK("get --value_hex a1", "0x6231", True)
217        self.assertRunOK("get --ttl a1", "b1")
218        self.assertRunOK("put a3 b3 --create_if_missing", "OK")
219        # fails because timstamp's length is greater than value's
220        self.assertRunFAIL("get --ttl a3")
221        self.assertRunOK("checkconsistency", "OK")
222
223    def testInvalidCmdLines(self):
224        print "Running testInvalidCmdLines..."
225        # db not specified
226        self.assertRunFAILFull("put 0x6133 0x6233 --hex --create_if_missing")
227        # No param called he
228        self.assertRunFAIL("put 0x6133 0x6233 --he --create_if_missing")
229        # max_keys is not applicable for put
230        self.assertRunFAIL("put 0x6133 0x6233 --max_keys=1 --create_if_missing")
231        # hex has invalid boolean value
232        self.assertRunFAIL("put 0x6133 0x6233 --hex=Boo --create_if_missing")
233
234    def testDumpLoad(self):
235        print "Running testDumpLoad..."
236        self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4",
237                "OK")
238        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
239        origDbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
240
241        # Dump and load without any additional params specified
242        dumpFilePath = os.path.join(self.TMP_DIR, "dump1")
243        loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump1")
244        self.assertTrue(self.dumpDb("--db=%s" % origDbPath, dumpFilePath))
245        self.assertTrue(self.loadDb(
246            "--db=%s --create_if_missing" % loadedDbPath, dumpFilePath))
247        self.assertRunOKFull("scan --db=%s" % loadedDbPath,
248                "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
249
250        # Dump and load in hex
251        dumpFilePath = os.path.join(self.TMP_DIR, "dump2")
252        loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump2")
253        self.assertTrue(self.dumpDb("--db=%s --hex" % origDbPath, dumpFilePath))
254        self.assertTrue(self.loadDb(
255            "--db=%s --hex --create_if_missing" % loadedDbPath, dumpFilePath))
256        self.assertRunOKFull("scan --db=%s" % loadedDbPath,
257                "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
258
259        # Dump only a portion of the key range
260        dumpFilePath = os.path.join(self.TMP_DIR, "dump3")
261        loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump3")
262        self.assertTrue(self.dumpDb(
263            "--db=%s --from=x1 --to=x3" % origDbPath, dumpFilePath))
264        self.assertTrue(self.loadDb(
265            "--db=%s --create_if_missing" % loadedDbPath, dumpFilePath))
266        self.assertRunOKFull("scan --db=%s" % loadedDbPath, "x1 : y1\nx2 : y2")
267
268        # Dump upto max_keys rows
269        dumpFilePath = os.path.join(self.TMP_DIR, "dump4")
270        loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump4")
271        self.assertTrue(self.dumpDb(
272            "--db=%s --max_keys=3" % origDbPath, dumpFilePath))
273        self.assertTrue(self.loadDb(
274            "--db=%s --create_if_missing" % loadedDbPath, dumpFilePath))
275        self.assertRunOKFull("scan --db=%s" % loadedDbPath,
276                "x1 : y1\nx2 : y2\nx3 : y3")
277
278        # Load into an existing db, create_if_missing is not specified
279        self.assertTrue(self.dumpDb("--db=%s" % origDbPath, dumpFilePath))
280        self.assertTrue(self.loadDb("--db=%s" % loadedDbPath, dumpFilePath))
281        self.assertRunOKFull("scan --db=%s" % loadedDbPath,
282                "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
283
284        # Dump and load with WAL disabled
285        dumpFilePath = os.path.join(self.TMP_DIR, "dump5")
286        loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump5")
287        self.assertTrue(self.dumpDb("--db=%s" % origDbPath, dumpFilePath))
288        self.assertTrue(self.loadDb(
289            "--db=%s --disable_wal --create_if_missing" % loadedDbPath,
290            dumpFilePath))
291        self.assertRunOKFull("scan --db=%s" % loadedDbPath,
292                "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
293
294        # Dump and load with lots of extra params specified
295        extraParams = " ".join(["--bloom_bits=14", "--compression_type=bzip2",
296                                "--block_size=1024", "--auto_compaction=true",
297                                "--write_buffer_size=4194304",
298                                "--file_size=2097152"])
299        dumpFilePath = os.path.join(self.TMP_DIR, "dump6")
300        loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump6")
301        self.assertTrue(self.dumpDb(
302            "--db=%s %s" % (origDbPath, extraParams), dumpFilePath))
303        self.assertTrue(self.loadDb(
304            "--db=%s %s --create_if_missing" % (loadedDbPath, extraParams),
305            dumpFilePath))
306        self.assertRunOKFull("scan --db=%s" % loadedDbPath,
307                "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
308
309        # Dump with count_only
310        dumpFilePath = os.path.join(self.TMP_DIR, "dump7")
311        loadedDbPath = os.path.join(self.TMP_DIR, "loaded_from_dump7")
312        self.assertTrue(self.dumpDb(
313            "--db=%s --count_only" % origDbPath, dumpFilePath))
314        self.assertTrue(self.loadDb(
315            "--db=%s --create_if_missing" % loadedDbPath, dumpFilePath))
316        # DB should have atleast one value for scan to work
317        self.assertRunOKFull("put --db=%s k1 v1" % loadedDbPath, "OK")
318        self.assertRunOKFull("scan --db=%s" % loadedDbPath, "k1 : v1")
319
320        # Dump command fails because of typo in params
321        dumpFilePath = os.path.join(self.TMP_DIR, "dump8")
322        self.assertFalse(self.dumpDb(
323            "--db=%s --create_if_missing" % origDbPath, dumpFilePath))
324
325    def testMiscAdminTask(self):
326        print "Running testMiscAdminTask..."
327        # These tests need to be improved; for example with asserts about
328        # whether compaction or level reduction actually took place.
329        self.assertRunOK("batchput --create_if_missing x1 y1 x2 y2 x3 y3 x4 y4",
330                "OK")
331        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
332        origDbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
333
334        self.assertTrue(0 == run_err_null(
335            "./ldb compact --db=%s" % origDbPath))
336        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
337
338        self.assertTrue(0 == run_err_null(
339            "./ldb reduce_levels --db=%s --new_levels=2" % origDbPath))
340        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
341
342        self.assertTrue(0 == run_err_null(
343            "./ldb reduce_levels --db=%s --new_levels=3" % origDbPath))
344        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
345
346        self.assertTrue(0 == run_err_null(
347            "./ldb compact --db=%s --from=x1 --to=x3" % origDbPath))
348        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
349
350        self.assertTrue(0 == run_err_null(
351            "./ldb compact --db=%s --hex --from=0x6131 --to=0x6134"
352            % origDbPath))
353        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
354
355        #TODO(dilip): Not sure what should be passed to WAL.Currently corrupted.
356        self.assertTrue(0 == run_err_null(
357            "./ldb dump_wal --db=%s --walfile=%s --header" % (
358                origDbPath, os.path.join(origDbPath, "LOG"))))
359        self.assertRunOK("scan", "x1 : y1\nx2 : y2\nx3 : y3\nx4 : y4")
360
361    def testCheckConsistency(self):
362        print "Running testCheckConsistency..."
363
364        dbPath = os.path.join(self.TMP_DIR, self.DB_NAME)
365        self.assertRunOK("put x1 y1 --create_if_missing", "OK")
366        self.assertRunOK("put x2 y2", "OK")
367        self.assertRunOK("get x1", "y1")
368        self.assertRunOK("checkconsistency", "OK")
369
370        sstFilePath = my_check_output("ls %s" % os.path.join(dbPath, "*.sst"),
371                                      shell=True)
372
373        # Modify the file
374        my_check_output("echo 'evil' > %s" % sstFilePath, shell=True)
375        self.assertRunFAIL("checkconsistency")
376
377        # Delete the file
378        my_check_output("rm -f %s" % sstFilePath, shell=True)
379        self.assertRunFAIL("checkconsistency")
380
381
382if __name__ == "__main__":
383    unittest.main()
384
Full Screen

cuts.py

Source: cuts.py Github

copy
1from ROOT import TCut
2
3#_______________________________________________________________________________
4def ANDtwo(cut1,cut2):
5    """AND of two TCuts in PyROOT"""
6    return TCut("(%s) && (%s)"%(cut1.GetTitle(),cut2.GetTitle()))
7
8
9#_______________________________________________________________________________
10def ORtwo(cut1,cut2):
11    """OR of two TCuts in PyROOT"""
12    return TCut("(%s) || (%s)"%(cut1.GetTitle(),cut2.GetTitle()))
13
14
15#_______________________________________________________________________________
16def AND(*arg):
17    """AND of any number of TCuts in PyROOT"""
18    length = len(arg)
19    if length == 0:
20        print "ERROR: invalid number of arguments"
21        return
22    if length == 1:
23        return arg[0] 
24    if length==2:
25        return ANDtwo(arg[0],arg[1])
26    if length>2:
27        result = arg[0]
28        for i in range(1,len(arg)):
29            result = ANDtwo(result,arg[i])
30        return result
31
32
33#_______________________________________________________________________________
34def OR(*arg): 
35    """OR of any number of TCuts in PyROOT"""
36    length = len(arg)
37    if length == 0:
38        print "ERROR: invalid number of arguments"
39        return
40    if length == 1:
41        return arg[0] 
42    if length==2:
43        return ORtwo(arg[0],arg[1])
44    if length>2:
45        result = arg[0]
46        for i in range(1,len(arg)):
47            result = ORtwo(result,arg[i])
48        return result
49
50
51#_______________________________________________________________________________
52nocut = TCut("")
53
54ok_eta = TCut("TMath::Abs(eta)>1.64 && TMath::Abs(eta)<2.14")
55ok_pt = TCut("pt > 20.")
56
57## CSC simhits & digis
58ok_sh1 = TCut("(has_csc_sh&1) > 0")
59ok_sh2 = TCut("(has_csc_sh&2) > 0")
60ok_st1 = TCut("(has_csc_strips&1) > 0")
61ok_st2 = TCut("(has_csc_strips&2) > 0")
62ok_w1 = TCut("(has_csc_wires&1) > 0")
63ok_w2 = TCut("(has_csc_wires&2) > 0")
64ok_digi1 = AND(ok_st1,ok_w1)
65ok_digi2 = AND(ok_st2,ok_w2)
66
67## CSC stub
68ok_lct1 = TCut("(has_lct&1) > 0")
69ok_lct2 = TCut("(has_lct&2) > 0")
70ok_alct1 = TCut("(has_alct&1) > 0")
71ok_alct2 = TCut("(has_alct&2) > 0")
72ok_clct1 = TCut("(has_clct&1) > 0")
73ok_clct2 = TCut("(has_clct&2) > 0")
74ok_lct_hs_min = TCut("hs_lct_odd > 4")
75ok_lct_hs_max = TCut("hs_lct_odd < 125")
76ok_lct_hs = AND(ok_lct_hs_min,ok_lct_hs_max)
77ok_lcths1 = AND(ok_lct1,ok_lct_hs)
78ok_lcths2 = AND(ok_lct2,ok_lct_hs)
79
80## GEM simhit
81ok_gsh1 = TCut("(has_gem_sh&1) > 0")
82ok_gsh2 = TCut("(has_gem_sh&2) > 0")
83ok_g2sh1 = TCut("(has_gem_sh2&1) > 0")
84ok_g2sh2 = TCut("(has_gem_sh2&2) > 0")
85
86
87## GEM digi
88ok_gdg1 = TCut("(has_gem_dg&1) > 0")
89ok_gdg2 = TCut("(has_gem_dg&2) > 0")
90ok_pad1 = TCut("(has_gem_pad&1) > 0")
91ok_pad2 = TCut("(has_gem_pad&2) > 0")
92
93ok_dphi1 = TCut("dphi_pad_odd < 10.")
94ok_dphi2 = TCut("dphi_pad_even < 10.")
95
96ok_pad1_lct1 = AND(ok_pad1,ok_lct1)
97ok_pad2_lct2 = AND(ok_pad2,ok_lct2)
98
99ok_pad1_dphi1 = AND(ok_pad1,ok_dphi1)
100ok_pad2_dphi2 = AND(ok_pad2,ok_dphi2)
101
102ok_lct1_eta = AND(ok_eta,ok_lct1)
103ok_lct2_eta = AND(ok_eta,ok_lct2)
104
105ok_pad1_lct1_eta = AND(ok_pad1,ok_lct1,ok_eta)
106ok_pad2_lct2_eta = AND(ok_pad2,ok_lct2,ok_eta)
107
108ok_gsh1_lct1_eta = AND(ok_gsh1,ok_lct1,ok_eta)
109ok_gsh2_lct2_eta = AND(ok_gsh2,ok_lct2,ok_eta)
110
111ok_gsh1_eta = AND(ok_gsh1,ok_eta)
112ok_gsh2_eta = AND(ok_gsh2,ok_eta)
113
114ok_gdg1_eta = AND(ok_gdg1,ok_eta)
115ok_gdg2_eta = AND(ok_gdg2,ok_eta)
116
117ok_2pad1 = TCut("(has_gem_pad2&1) > 0")
118ok_2pad2 = TCut("(has_gem_pad2&2) > 0")
119
120ok_pad1_overlap = OR(ok_pad1,AND(ok_lct2,ok_pad2))
121ok_pad2_overlap = OR(ok_pad2,AND(ok_lct1,ok_pad1))
122
123ok_copad1 = TCut("(has_gem_copad&1) > 0")
124ok_copad2 = TCut("(has_gem_copad&2) > 0")
125
126ok_Qp = TCut("charge > 0")
127ok_Qn = TCut("charge < 0")
128
129ok_lct1_eta_Qn = AND(ok_lct1,ok_eta,ok_Qn)
130ok_lct2_eta_Qn = AND(ok_lct2,ok_eta,ok_Qn)
131
132ok_lct1_eta_Qp = AND(ok_lct1,ok_eta,ok_Qp)
133ok_lct2_eta_Qp = AND(ok_lct2,ok_eta,ok_Qp)
134
135Ep = TCut("endcap > 0")
136En = TCut("endcap < 0")
137
138
Full Screen

Vector4.js

Source: Vector4.js Github

copy
1/**
2 * @author bhouston / http://exocortex.com
3 */
4
5module( "Vector4" );
6
7test( "constructor", function() {
8	var a = new THREE.Vector4();
9	ok( a.x == 0, "Passed!" );
10	ok( a.y == 0, "Passed!" );
11	ok( a.z == 0, "Passed!" );
12	ok( a.w == 1, "Passed!" );
13
14	a = new THREE.Vector4( x, y, z, w );
15	ok( a.x === x, "Passed!" );
16	ok( a.y === y, "Passed!" );
17	ok( a.z === z, "Passed!" );
18	ok( a.w === w, "Passed!" );
19});
20
21test( "copy", function() {
22	var a = new THREE.Vector4( x, y, z, w );
23	var b = new THREE.Vector4().copy( a );
24	ok( b.x == x, "Passed!" );
25	ok( b.y == y, "Passed!" );
26	ok( b.z == z, "Passed!" );
27	ok( b.w == w, "Passed!" );
28
29	// ensure that it is a true copy
30	a.x = 0;
31	a.y = -1;
32	a.z = -2;
33	a.w = -3;
34	ok( b.x == x, "Passed!" );
35	ok( b.y == y, "Passed!" );
36	ok( b.z == z, "Passed!" );
37	ok( b.w == w, "Passed!" );
38});
39
40test( "set", function() {
41	var a = new THREE.Vector4();
42	ok( a.x == 0, "Passed!" );
43	ok( a.y == 0, "Passed!" );
44	ok( a.z == 0, "Passed!" );
45	ok( a.w == 1, "Passed!" );
46
47	a.set( x, y, z, w );
48	ok( a.x == x, "Passed!" );
49	ok( a.y == y, "Passed!" );
50	ok( a.z == z, "Passed!" );
51	ok( a.w == w, "Passed!" );
52});
53
54test( "setX,setY,setZ,setW", function() {
55	var a = new THREE.Vector4();
56	ok( a.x == 0, "Passed!" );
57	ok( a.y == 0, "Passed!" );
58	ok( a.z == 0, "Passed!" );
59	ok( a.w == 1, "Passed!" );
60
61	a.setX( x );
62	a.setY( y );
63	a.setZ( z );
64	a.setW( w );
65
66	ok( a.x == x, "Passed!" );
67	ok( a.y == y, "Passed!" );
68	ok( a.z == z, "Passed!" );
69	ok( a.w == w, "Passed!" );
70});
71
72test( "setComponent,getComponent", function() {
73	var a = new THREE.Vector4();
74	ok( a.x == 0, "Passed!" );
75	ok( a.y == 0, "Passed!" );
76	ok( a.z == 0, "Passed!" );
77	ok( a.w == 1, "Passed!" );
78
79	a.setComponent( 0, 1 );
80	a.setComponent( 1, 2 );
81	a.setComponent( 2, 3 );
82	a.setComponent( 3, 4 );
83	ok( a.getComponent( 0 ) == 1, "Passed!" );
84	ok( a.getComponent( 1 ) == 2, "Passed!" );
85	ok( a.getComponent( 2 ) == 3, "Passed!" );
86	ok( a.getComponent( 3 ) == 4, "Passed!" );
87});
88
89test( "add", function() {
90	var a = new THREE.Vector4( x, y, z, w );
91	var b = new THREE.Vector4( -x, -y, -z, -w );
92
93	a.add( b );
94	ok( a.x == 0, "Passed!" );
95	ok( a.y == 0, "Passed!" );
96	ok( a.z == 0, "Passed!" );
97	ok( a.w == 0, "Passed!" );
98
99	var c = new THREE.Vector4().addVectors( b, b );
100	ok( c.x == -2*x, "Passed!" );
101	ok( c.y == -2*y, "Passed!" );
102	ok( c.z == -2*z, "Passed!" );
103	ok( c.w == -2*w, "Passed!" );
104});
105
106test( "sub", function() {
107	var a = new THREE.Vector4( x, y, z, w );
108	var b = new THREE.Vector4( -x, -y, -z, -w );
109
110	a.sub( b );
111	ok( a.x == 2*x, "Passed!" );
112	ok( a.y == 2*y, "Passed!" );
113	ok( a.z == 2*z, "Passed!" );
114	ok( a.w == 2*w, "Passed!" );
115
116	var c = new THREE.Vector4().subVectors( a, a );
117	ok( c.x == 0, "Passed!" );
118	ok( c.y == 0, "Passed!" );
119	ok( c.z == 0, "Passed!" );
120	ok( c.w == 0, "Passed!" );
121});
122
123test( "multiply/divide", function() {
124	var a = new THREE.Vector4( x, y, z, w );
125	var b = new THREE.Vector4( -x, -y, -z, -w );
126
127	a.multiplyScalar( -2 );
128	ok( a.x == x*-2, "Passed!" );
129	ok( a.y == y*-2, "Passed!" );
130	ok( a.z == z*-2, "Passed!" );
131	ok( a.w == w*-2, "Passed!" );
132
133	b.multiplyScalar( -2 );
134	ok( b.x == 2*x, "Passed!" );
135	ok( b.y == 2*y, "Passed!" );	
136	ok( b.z == 2*z, "Passed!" );	
137	ok( b.w == 2*w, "Passed!" );	
138
139	a.divideScalar( -2 );
140	ok( a.x == x, "Passed!" );
141	ok( a.y == y, "Passed!" );
142	ok( a.z == z, "Passed!" );
143	ok( a.w == w, "Passed!" );
144
145	b.divideScalar( -2 );
146	ok( b.x == -x, "Passed!" );
147	ok( b.y == -y, "Passed!" );
148	ok( b.z == -z, "Passed!" );
149	ok( b.w == -w, "Passed!" );
150});
151
152test( "min/max/clamp", function() {
153	var a = new THREE.Vector4( x, y, z, w );
154	var b = new THREE.Vector4( -x, -y, -z, -w );
155	var c = new THREE.Vector4();
156
157	c.copy( a ).min( b );
158	ok( c.x == -x, "Passed!" );
159	ok( c.y == -y, "Passed!" );
160	ok( c.z == -z, "Passed!" );
161	ok( c.w == -w, "Passed!" );
162
163	c.copy( a ).max( b );
164	ok( c.x == x, "Passed!" );
165	ok( c.y == y, "Passed!" );
166	ok( c.z == z, "Passed!" );
167	ok( c.w == w, "Passed!" );
168
169	c.set( -2*x, 2*y, -2*z, 2*w );
170	c.clamp( b, a );
171	ok( c.x == -x, "Passed!" );
172	ok( c.y == y, "Passed!" );
173	ok( c.z == -z, "Passed!" );
174	ok( c.w == w, "Passed!" );
175});
176
177test( "negate", function() {
178	var a = new THREE.Vector4( x, y, z, w );
179
180	a.negate();
181	ok( a.x == -x, "Passed!" );
182	ok( a.y == -y, "Passed!" );
183	ok( a.z == -z, "Passed!" );
184	ok( a.w == -w, "Passed!" );
185});
186
187test( "dot", function() {
188	var a = new THREE.Vector4( x, y, z, w );
189	var b = new THREE.Vector4( -x, -y, -z, -w );
190	var c = new THREE.Vector4( 0, 0, 0, 0 );
191
192	var result = a.dot( b );
193	ok( result == (-x*x-y*y-z*z-w*w), "Passed!" );
194
195	result = a.dot( c );
196	ok( result == 0, "Passed!" );
197});
198
199test( "length/lengthSq", function() {
200	var a = new THREE.Vector4( x, 0, 0, 0 );
201	var b = new THREE.Vector4( 0, -y, 0, 0 );
202	var c = new THREE.Vector4( 0, 0, z, 0 );
203	var d = new THREE.Vector4( 0, 0, 0, w );
204	var e = new THREE.Vector4( 0, 0, 0, 0 );
205	
206	ok( a.length() == x, "Passed!" );
207	ok( a.lengthSq() == x*x, "Passed!" );
208	ok( b.length() == y, "Passed!" );
209	ok( b.lengthSq() == y*y, "Passed!" );
210	ok( c.length() == z, "Passed!" );
211	ok( c.lengthSq() == z*z, "Passed!" );
212	ok( d.length() == w, "Passed!" );
213	ok( d.lengthSq() == w*w, "Passed!" );
214	ok( e.length() == 0, "Passed!" );
215	ok( e.lengthSq() == 0, "Passed!" );
216
217	a.set( x, y, z, w );
218	ok( a.length() == Math.sqrt( x*x + y*y + z*z + w*w ), "Passed!" );
219	ok( a.lengthSq() == ( x*x + y*y + z*z + w*w ), "Passed!" );
220});
221
222test( "normalize", function() {
223	var a = new THREE.Vector4( x, 0, 0, 0 );
224	var b = new THREE.Vector4( 0, -y, 0, 0 );
225	var c = new THREE.Vector4( 0, 0, z, 0 );
226	var d = new THREE.Vector4( 0, 0, 0, -w );
227	
228	a.normalize();
229	ok( a.length() == 1, "Passed!" );
230	ok( a.x == 1, "Passed!" );
231
232	b.normalize();
233	ok( b.length() == 1, "Passed!" );
234	ok( b.y == -1, "Passed!" );
235
236	c.normalize();
237	ok( c.length() == 1, "Passed!" );
238	ok( c.z == 1, "Passed!" );
239
240	d.normalize();
241	ok( d.length() == 1, "Passed!" );
242	ok( d.w == -1, "Passed!" );
243});
244
245/*
246test( "distanceTo/distanceToSquared", function() {
247	var a = new THREE.Vector4( x, 0, 0, 0 );
248	var b = new THREE.Vector4( 0, -y, 0, 0 );
249	var c = new THREE.Vector4( 0, 0, z, 0 );
250	var d = new THREE.Vector4( 0, 0, 0, -w );
251	var e = new THREE.Vector4();
252	
253	ok( a.distanceTo( e ) == x, "Passed!" );
254	ok( a.distanceToSquared( e ) == x*x, "Passed!" );
255
256	ok( b.distanceTo( e ) == y, "Passed!" );
257	ok( b.distanceToSquared( e ) == y*y, "Passed!" );
258
259	ok( c.distanceTo( e ) == z, "Passed!" );
260	ok( c.distanceToSquared( e ) == z*z, "Passed!" );
261
262	ok( d.distanceTo( e ) == w, "Passed!" );
263	ok( d.distanceToSquared( e ) == w*w, "Passed!" );
264});
265*/
266
267
268test( "setLength", function() {
269	var a = new THREE.Vector4( x, 0, 0, 0 );
270
271	ok( a.length() == x, "Passed!" );
272	a.setLength( y );
273	ok( a.length() == y, "Passed!" );
274
275	a = new THREE.Vector4( 0, 0, 0, 0 );
276	ok( a.length() == 0, "Passed!" );
277	a.setLength( y );
278	ok( a.length() == 0, "Passed!" );
279});
280
281test( "lerp/clone", function() {
282	var a = new THREE.Vector4( x, 0, z, 0 );
283	var b = new THREE.Vector4( 0, -y, 0, -w );
284
285	ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
286	ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
287
288	ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
289
290	ok( a.clone().lerp( b, 0.5 ).x == x*0.5, "Passed!" );
291	ok( a.clone().lerp( b, 0.5 ).y == -y*0.5, "Passed!" );
292	ok( a.clone().lerp( b, 0.5 ).z == z*0.5, "Passed!" );
293	ok( a.clone().lerp( b, 0.5 ).w == -w*0.5, "Passed!" );
294
295	ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
296});
297
298test( "equals", function() {
299	var a = new THREE.Vector4( x, 0, z, 0 );
300	var b = new THREE.Vector4( 0, -y, 0, -w );
301
302	ok( a.x != b.x, "Passed!" );
303	ok( a.y != b.y, "Passed!" );
304	ok( a.z != b.z, "Passed!" );
305	ok( a.w != b.w, "Passed!" );
306
307	ok( ! a.equals( b ), "Passed!" );
308	ok( ! b.equals( a ), "Passed!" );
309
310	a.copy( b );
311	ok( a.x == b.x, "Passed!" );
312	ok( a.y == b.y, "Passed!" );
313	ok( a.z == b.z, "Passed!" );
314	ok( a.w == b.w, "Passed!" );
315
316	ok( a.equals( b ), "Passed!" );
317	ok( b.equals( a ), "Passed!" );
318});
319
Full Screen

test_pubsub_1_2_1.js

Source: test_pubsub_1_2_1.js Github

copy
1/*******************************************************************************
2 * test_pubsub_1_2_1.js:
3 *      Component of the DOH-based test suite for the OpenAjax Hub.
4 *
5 *      JavaScript logic for the unit test for routines having to do with managing event
6 *      publishing and event subscribing. (The "event hub" or "topic bus".)
7 *      [ This is a port of the Hub 1.0 testcases found in _TestPubSub.js. ]
8 *
9 * Copyright 2008 OpenAjax Alliance
10 *
11 * Licensed under the Apache License, Version 2.0 (the "License"); you may not 
12 * use this file except in compliance with the License. You may obtain a copy 
13 * of the License at http://www.apache.org/licenses/LICENSE-2.0 . Unless 
14 * required by applicable law or agreed to in writing, software distributed 
15 * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
16 * CONDITIONS OF ANY KIND, either express or implied. See the License for the 
17 * specific language governing permissions and limitations under the License.
18 *
19 ******************************************************************************/
20
21/***********************************************************************
22 *  js1_2_1
23 **********************************************************************/
24
25var js1_2_1 = {
26	name: "1.2.1",
27	description: "Event unit tests",
28	sub: null,
29	events: [
30		{ s: "abc", p: "abc", ex: false, ok: true },
31		{ s: "abc", p: "def", ex: false, ok: false },
32		{ s: "abc", p: "ab", ex: false, ok: false },
33		{ s: "*", p: "abc", ex: false, ok: true },
34		{ s: "**", p: "abc", ex: false, ok: true },
35		{ s: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", p: "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", ex: false, ok: true },
36		{ s: "**", p: "abc.def.ghi", ex: false, ok: true },
37		{ s: "*", p: "abc.def", ex: false, ok: false },
38		{ s: "a", p: "a", ex: false, ok: true },
39		{ s: "**", p: "abc", ex: false, ok: true },
40		{ s: "com.tibco", p: "com.tibco", ex: false, ok: true },
41		{ s: "com.*", p: "com.tibco", ex: false, ok: true },
42		{ s: "*.tibco", p: "com.tibco", ex: false, ok: true },
43		{ s: "*.*", p: "com.tibco", ex: false, ok: true },
44		{ s: "*.**", p: "com.tibco", ex: false, ok: true },
45		{ s: "com.tibco", p: "com.tibco.foo", ex: false, ok: false },
46		{ s: "com.tibco", p: "com", ex: false, ok: false },
47		{ s: "com.tibco", p: "com.tibco", ex: false, ok: true },
48		{ s: "a.b.c", p: "a.b.c", ex: false, ok: true },
49		{ s: "a.b.*", p: "a.b.c", ex: false, ok: true },
50		{ s: "a.*.c", p: "a.b.c", ex: false, ok: true },
51		{ s: "*.b.c", p: "a.b.c", ex: false, ok: true },
52		{ s: "*.*.c", p: "a.b.c", ex: false, ok: true },
53		{ s: "a.*.*", p: "a.b.c", ex: false, ok: true },
54		{ s: "*.*.*", p: "a.b.c", ex: false, ok: true },
55		{ s: "*.**", p: "a.b.c", ex: false, ok: true },
56		{ s: "a.b.c", p: "a.b.c", ex: false, ok: true },
57		{ s: "a.b.c.d.e.f.g.h.i.j", p: "a.b.c.d.e.f.g.h.i.j", ex: false, ok: true },
58		{ s: "a.**", p: "a.b.c.d.e.f.g.h.i.j", ex: false, ok: true },
59		{ s: "aa.*.cc.*.e.f.g.h.i.j", p: "aa.b.cc.d.e.f.g.h.i.j", ex: false, ok: true },
60		{ s: "1", p: "1", ex: false, ok: true },
61		{ s: "*", p: "1", ex: false, ok: true },
62		{ s: "1.0", p: "1.0", ex: false, ok: true },
63		{ s: "1.0.5", p: "1.0.5", ex: false, ok: true },
64		{ s: "1.0.*", p: "1.0.5", ex: false, ok: true },
65		{ s: "*.1.0", p: "1.1.0", ex: false, ok: true },
66		{ s: "false", p: "false", ex: false, ok: true },
67		{ s: "false.true", p: "false.true", ex: false, ok: true },
68		{ s: "return", p: "return", ex: false, ok: true },
69		{ s: "x.length", p: "x.length", ex: false, ok: true },
70		{ s: "function", p: "function", ex: false, ok: true },
71		{ s: "null", p: "null", ex: false, ok: true },
72		{ s: "*", p: "null", ex: false, ok: true },
73		{ s: "this", p: "this", ex: false, ok: true },
74		{ s: "*", p: "this", ex: false, ok: true },
75		{ s: "abc=", p: "abc=", ex: false, ok: true },
76		{ s: "二.重.橋", p: "二.重.橋", ex: false, ok: true },
77		{ s: "*.重.橋", p: "二.重.橋", ex: false, ok: true },
78		{ s: "二.*.橋", p: "二.重.橋", ex: false, ok: true },
79		{ s: "二.**", p: "二.重.橋", ex: false, ok: true },
80		{ s: "**", p: "二.重.橋", ex: false, ok: true },
81		{ s: "$", p: "$", ex: false, ok: true },
82		{ s: "a/b.c/d", p: "a/b.c/d", ex: false, ok: true }, 
83		{ s: "[.]", p: "[.]", ex: false, ok: true },
84		{ s: "^.&", p: "^.&", ex: false, ok: true },
85		{ s: "@.%.#.).(,;.A", p: "@.%.#.).(,;.A", ex: false, ok: true },
86		{ s: "A.B.C", p: "a.b.c", ex: false, ok: false },
87		{ s: "a.b.c", p: "A.B.C", ex: false, ok: false }
88
89
90	],
91	result: "",
92	expectedResult: "1.2.1: start, OK: cb: abc, OK: completed 0, OK: completed 1, OK: completed 2, "+
93		"OK: cb: abc, OK: completed 3, "+
94		"OK: cb: abc, OK: completed 4, "+
95		"OK: cb: aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, "+
96		"OK: completed 5, OK: cb: abc.def.ghi, OK: completed 6, OK: completed 7, OK: cb: a, "+
97		"OK: completed 8, OK: cb: abc, OK: completed 9, OK: cb: com.tibco, OK: completed 10, "+
98		"OK: cb: com.tibco, OK: completed 11, "+
99
100
101		"OK: cb: com.tibco, OK: completed 12, OK: cb: com.tibco, OK: completed 13, OK: cb: com.tibco, "+
102		"OK: completed 14, OK: completed 15, OK: completed 16, OK: cb: com.tibco, OK: completed 17, "+
103		"OK: cb: a.b.c, OK: completed 18, OK: cb: a.b.c, OK: completed 19, OK: cb: a.b.c, OK: completed 20, "+
104		"OK: cb: a.b.c, OK: completed 21, OK: cb: a.b.c, OK: completed 22, OK: cb: a.b.c, OK: completed 23, "+
105		"OK: cb: a.b.c, OK: completed 24, OK: cb: a.b.c, OK: completed 25, OK: cb: a.b.c, OK: completed 26, "+
106		"OK: cb: a.b.c.d.e.f.g.h.i.j, OK: completed 27, OK: cb: a.b.c.d.e.f.g.h.i.j, OK: completed 28, "+
107		"OK: cb: aa.b.cc.d.e.f.g.h.i.j, OK: completed 29, "+
108
109
110		"OK: cb: 1, OK: completed 30, OK: cb: 1, "+
111		"OK: completed 31, OK: cb: 1.0, OK: completed 32, OK: cb: 1.0.5, OK: completed 33, OK: cb: 1.0.5, "+
112		"OK: completed 34, OK: cb: 1.1.0, OK: completed 35, OK: cb: false, OK: completed 36, OK: cb: false.true, "+
113		"OK: completed 37, OK: cb: return, OK: completed 38, OK: cb: x.length, OK: completed 39, "+
114		"OK: cb: function, OK: completed 40, OK: cb: null, OK: completed 41, OK: cb: null, "+
115		"OK: completed 42, OK: cb: this, OK: completed 43, OK: cb: this, OK: completed 44, OK: cb: abc=, OK: completed 45, "+
116		"OK: cb: 二.重.橋, OK: completed 46, " +
117		"OK: cb: 二.重.橋, OK: completed 47, " +
118		"OK: cb: 二.重.橋, OK: completed 48, " +
119		"OK: cb: 二.重.橋, OK: completed 49, " +
120		"OK: cb: 二.重.橋, OK: completed 50, " +
121		"OK: cb: $, OK: completed 51, " +
122		"OK: cb: a/b.c/d, OK: completed 52, " +
123		"OK: cb: [.], OK: completed 53, " +
124		"OK: cb: ^.&, OK: completed 54, " +
125		"OK: cb: @.%.#.).(,;.A, OK: completed 55, " +
126		"OK: completed 56, "  +
127		"OK: completed 57, "
128}
129
130js1_2_1.cb = function(event, message, subscriberData) {
131	// Ignore the next/finish orchestration events which might come here due to wildcard subscriptions
132	if (event !== "js1_2_1.nextEvent" && event !== "js1_2_1.finish") {
133		this.result += ("OK: cb: " + event + ", ");
134	}
135	return;
136}
137
138js1_2_1.run = function() {
139	this.result = "1.2.1: start, ";
140	this.hubClient.subscribe("js1_2_1.finish", js1_2_1.finish_cb, this, function( subscriptionID, success, errCode ) {
141		this.hubClient.subscribe("js1_2_1.nextEvent", js1_2_1.nextEvent_cb, this, function( subscriptionID, success, errCode ) {
142			this.hubClient.publish("js1_2_1.nextEvent", {eventIndex:0, subscriptionID: ""});
143		});
144	});
145
146}
147
148js1_2_1.nextEvent_cb = function(event, message, subscriberData) {
149	var i = message.eventIndex;
150	var subID = message.subscriptionID;
151	if (i == 0) {
152		this.hubClient.subscribe(js1_2_1.events[i].s, js1_2_1.cb, this, function( subscriptionID, success, errCode ) {
153			var new_subID = subscriptionID;
154			this.hubClient.publish(js1_2_1.events[i].p, {});
155			if ((i+1) < js1_2_1.events.length) {
156				this.hubClient.publish("js1_2_1.nextEvent", {eventIndex:i+1, subscriptionID: new_subID});
157			} else {
158				this.hubClient.publish("js1_2_1.finish", null);
159			}
160		}, null);
161	} else {
162		this.hubClient.unsubscribe(subID, function( subscriptionID, success, errCode ) {
163			this.result += ("OK: completed " + (i-1) + ", ");
164			if (i < js1_2_1.events.length) {
165				this.hubClient.subscribe(js1_2_1.events[i].s, js1_2_1.cb, this, function( subscriptionID, success, errCode ) {
166					var new_subID = subscriptionID;
167					this.hubClient.publish(js1_2_1.events[i].p, {});
168						this.hubClient.publish("js1_2_1.nextEvent", {eventIndex:i+1, subscriptionID: new_subID});
169				}, null);
170			} else {
171				this.hubClient.publish("js1_2_1.finish", null);
172			}
173		}, this);
174	}
175}
176
177js1_2_1.finish_cb = function(event, message, subscriberData) {
178	if (this.result == js1_2_1.expectedResult) {
179		this.sendMsg( ["done"] );
180	} else {
181		this.sendMsg( ["error", "Incorrect final results for pubsub js1_2_1"] );
182	}
183}
184
Full Screen

Vector3.js

Source: Vector3.js Github

copy
1/**
2 * @author bhouston / http://exocortex.com
3 */
4
5module( "Vector3" );
6
7test( "constructor", function() {
8	var a = new THREE.Vector3();
9	ok( a.x == 0, "Passed!" );
10	ok( a.y == 0, "Passed!" );
11	ok( a.z == 0, "Passed!" );
12
13	a = new THREE.Vector3( x, y, z );
14	ok( a.x === x, "Passed!" );
15	ok( a.y === y, "Passed!" );
16	ok( a.z === z, "Passed!" );
17});
18
19test( "copy", function() {
20	var a = new THREE.Vector3( x, y, z );
21	var b = new THREE.Vector3().copy( a );
22	ok( b.x == x, "Passed!" );
23	ok( b.y == y, "Passed!" );
24	ok( b.z == z, "Passed!" );
25
26	// ensure that it is a true copy
27	a.x = 0;
28	a.y = -1;
29	a.z = -2;
30	ok( b.x == x, "Passed!" );
31	ok( b.y == y, "Passed!" );
32	ok( b.z == z, "Passed!" );
33});
34
35test( "set", function() {
36	var a = new THREE.Vector3();
37	ok( a.x == 0, "Passed!" );
38	ok( a.y == 0, "Passed!" );
39	ok( a.z == 0, "Passed!" );
40
41	a.set( x, y, z );
42	ok( a.x == x, "Passed!" );
43	ok( a.y == y, "Passed!" );
44	ok( a.z == z, "Passed!" );
45});
46
47test( "setX,setY,setZ", function() {
48	var a = new THREE.Vector3();
49	ok( a.x == 0, "Passed!" );
50	ok( a.y == 0, "Passed!" );
51	ok( a.z == 0, "Passed!" );
52
53	a.setX( x );
54	a.setY( y );
55	a.setZ( z );
56
57	ok( a.x == x, "Passed!" );
58	ok( a.y == y, "Passed!" );
59	ok( a.z == z, "Passed!" );
60});
61
62test( "setComponent,getComponent", function() {
63	var a = new THREE.Vector3();
64	ok( a.x == 0, "Passed!" );
65	ok( a.y == 0, "Passed!" );
66	ok( a.z == 0, "Passed!" );
67
68	a.setComponent( 0, 1 );
69	a.setComponent( 1, 2 );
70	a.setComponent( 2, 3 );
71	ok( a.getComponent( 0 ) == 1, "Passed!" );
72	ok( a.getComponent( 1 ) == 2, "Passed!" );
73	ok( a.getComponent( 2 ) == 3, "Passed!" );
74});
75
76test( "add", function() {
77	var a = new THREE.Vector3( x, y, z );
78	var b = new THREE.Vector3( -x, -y, -z );
79
80	a.add( b );
81	ok( a.x == 0, "Passed!" );
82	ok( a.y == 0, "Passed!" );
83	ok( a.z == 0, "Passed!" );
84
85	var c = new THREE.Vector3().addVectors( b, b );
86	ok( c.x == -2*x, "Passed!" );
87	ok( c.y == -2*y, "Passed!" );
88	ok( c.z == -2*z, "Passed!" );
89});
90
91test( "sub", function() {
92	var a = new THREE.Vector3( x, y, z );
93	var b = new THREE.Vector3( -x, -y, -z );
94
95	a.sub( b );
96	ok( a.x == 2*x, "Passed!" );
97	ok( a.y == 2*y, "Passed!" );
98	ok( a.z == 2*z, "Passed!" );
99
100	var c = new THREE.Vector3().subVectors( a, a );
101	ok( c.x == 0, "Passed!" );
102	ok( c.y == 0, "Passed!" );
103	ok( c.z == 0, "Passed!" );
104});
105
106test( "multiply/divide", function() {
107	var a = new THREE.Vector3( x, y, z );
108	var b = new THREE.Vector3( -x, -y, -z );
109
110	a.multiplyScalar( -2 );
111	ok( a.x == x*-2, "Passed!" );
112	ok( a.y == y*-2, "Passed!" );
113	ok( a.z == z*-2, "Passed!" );
114
115	b.multiplyScalar( -2 );
116	ok( b.x == 2*x, "Passed!" );
117	ok( b.y == 2*y, "Passed!" );
118	ok( b.z == 2*z, "Passed!" );
119
120	a.divideScalar( -2 );
121	ok( a.x == x, "Passed!" );
122	ok( a.y == y, "Passed!" );
123	ok( a.z == z, "Passed!" );
124
125	b.divideScalar( -2 );
126	ok( b.x == -x, "Passed!" );
127	ok( b.y == -y, "Passed!" );
128	ok( b.z == -z, "Passed!" );
129});
130
131test( "min/max/clamp", function() {
132	var a = new THREE.Vector3( x, y, z );
133	var b = new THREE.Vector3( -x, -y, -z );
134	var c = new THREE.Vector3();
135
136	c.copy( a ).min( b );
137	ok( c.x == -x, "Passed!" );
138	ok( c.y == -y, "Passed!" );
139	ok( c.z == -z, "Passed!" );
140
141	c.copy( a ).max( b );
142	ok( c.x == x, "Passed!" );
143	ok( c.y == y, "Passed!" );
144	ok( c.z == z, "Passed!" );
145
146	c.set( -2*x, 2*y, -2*z );
147	c.clamp( b, a );
148	ok( c.x == -x, "Passed!" );
149	ok( c.y == y, "Passed!" );
150	ok( c.z == -z, "Passed!" );
151});
152
153test( "negate", function() {
154	var a = new THREE.Vector3( x, y, z );
155
156	a.negate();
157	ok( a.x == -x, "Passed!" );
158	ok( a.y == -y, "Passed!" );
159	ok( a.z == -z, "Passed!" );
160});
161
162test( "dot", function() {
163	var a = new THREE.Vector3( x, y, z );
164	var b = new THREE.Vector3( -x, -y, -z );
165	var c = new THREE.Vector3();
166
167	var result = a.dot( b );
168	ok( result == (-x*x-y*y-z*z), "Passed!" );
169
170	result = a.dot( c );
171	ok( result == 0, "Passed!" );
172});
173
174test( "length/lengthSq", function() {
175	var a = new THREE.Vector3( x, 0, 0 );
176	var b = new THREE.Vector3( 0, -y, 0 );
177	var c = new THREE.Vector3( 0, 0, z );
178	var d = new THREE.Vector3();
179
180	ok( a.length() == x, "Passed!" );
181	ok( a.lengthSq() == x*x, "Passed!" );
182	ok( b.length() == y, "Passed!" );
183	ok( b.lengthSq() == y*y, "Passed!" );
184	ok( c.length() == z, "Passed!" );
185	ok( c.lengthSq() == z*z, "Passed!" );
186	ok( d.length() == 0, "Passed!" );
187	ok( d.lengthSq() == 0, "Passed!" );
188
189	a.set( x, y, z );
190	ok( a.length() == Math.sqrt( x*x + y*y + z*z ), "Passed!" );
191	ok( a.lengthSq() == ( x*x + y*y + z*z ), "Passed!" );
192});
193
194test( "normalize", function() {
195	var a = new THREE.Vector3( x, 0, 0 );
196	var b = new THREE.Vector3( 0, -y, 0 );
197	var c = new THREE.Vector3( 0, 0, z );
198
199	a.normalize();
200	ok( a.length() == 1, "Passed!" );
201	ok( a.x == 1, "Passed!" );
202
203	b.normalize();
204	ok( b.length() == 1, "Passed!" );
205	ok( b.y == -1, "Passed!" );
206
207	c.normalize();
208	ok( c.length() == 1, "Passed!" );
209	ok( c.z == 1, "Passed!" );
210});
211
212test( "distanceTo/distanceToSquared", function() {
213	var a = new THREE.Vector3( x, 0, 0 );
214	var b = new THREE.Vector3( 0, -y, 0 );
215	var c = new THREE.Vector3( 0, 0, z );
216	var d = new THREE.Vector3();
217
218	ok( a.distanceTo( d ) == x, "Passed!" );
219	ok( a.distanceToSquared( d ) == x*x, "Passed!" );
220
221	ok( b.distanceTo( d ) == y, "Passed!" );
222	ok( b.distanceToSquared( d ) == y*y, "Passed!" );
223
224	ok( c.distanceTo( d ) == z, "Passed!" );
225	ok( c.distanceToSquared( d ) == z*z, "Passed!" );
226});
227
228test( "setLength", function() {
229	var a = new THREE.Vector3( x, 0, 0 );
230
231	ok( a.length() == x, "Passed!" );
232	a.setLength( y );
233	ok( a.length() == y, "Passed!" );
234
235	a = new THREE.Vector3( 0, 0, 0 );
236	ok( a.length() == 0, "Passed!" );
237	a.setLength( y );
238	ok( a.length() == 0, "Passed!" );
239
240});
241
242test( "projectOnVector", function() {
243	var a = new THREE.Vector3( 1, 0, 0 );
244	var b = new THREE.Vector3();
245	var normal = new THREE.Vector3( 10, 0, 0 );
246
247	ok( b.copy( a ).projectOnVector( normal ).equals( new THREE.Vector3( 1, 0, 0 ) ), "Passed!" );
248
249	a.set( 0, 1, 0 );
250	ok( b.copy( a ).projectOnVector( normal ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
251
252	a.set( 0, 0, -1 );
253	ok( b.copy( a ).projectOnVector( normal ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
254
255	a.set( -1, 0, 0 );
256	ok( b.copy( a ).projectOnVector( normal ).equals( new THREE.Vector3( -1, 0, 0 ) ), "Passed!" );
257
258});
259
260test( "projectOnPlane", function() {
261	var a = new THREE.Vector3( 1, 0, 0 );
262	var b = new THREE.Vector3();
263	var normal = new THREE.Vector3( 1, 0, 0 );
264
265	ok( b.copy( a ).projectOnPlane( normal ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
266
267	a.set( 0, 1, 0 );
268	ok( b.copy( a ).projectOnPlane( normal ).equals( new THREE.Vector3( 0, 1, 0 ) ), "Passed!" );
269
270	a.set( 0, 0, -1 );
271	ok( b.copy( a ).projectOnPlane( normal ).equals( new THREE.Vector3( 0, 0, -1 ) ), "Passed!" );
272
273	a.set( -1, 0, 0 );
274	ok( b.copy( a ).projectOnPlane( normal ).equals( new THREE.Vector3( 0, 0, 0 ) ), "Passed!" );
275
276});
277
278test( "reflect", function() {
279	var a = new THREE.Vector3();
280	var normal = new THREE.Vector3( 0, 1, 0 );
281	var b = new THREE.Vector3();
282
283	a.set( 0, -1, 0 );
284	ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( 0, 1, 0 ) ), "Passed!" );
285
286	a.set( 1, -1, 0 );
287	ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" );
288
289	a.set( 1, -1, 0 );
290	normal.set( 0, -1, 0 );
291	ok( b.copy( a ).reflect( normal ).equals( new THREE.Vector3( 1, 1, 0 ) ), "Passed!" );
292});
293
294test( "angleTo", function() {
295	var a = new THREE.Vector3( 0, -0.18851655680720186, 0.9820700116639124 );
296	var b = new THREE.Vector3( 0, 0.18851655680720186, -0.9820700116639124 );
297
298	equal( a.angleTo( a ), 0 );
299	equal( a.angleTo( b ), Math.PI );
300
301	var x = new THREE.Vector3( 1, 0, 0 );
302	var y = new THREE.Vector3( 0, 1, 0 );
303	var z = new THREE.Vector3( 0, 0, 1 );
304
305	equal( x.angleTo( y ), Math.PI / 2 );
306	equal( x.angleTo( z ), Math.PI / 2 );
307	equal( z.angleTo( x ), Math.PI / 2 );
308
309	ok( Math.abs( x.angleTo( new THREE.Vector3( 1, 1, 0 ) ) - ( Math.PI / 4 ) ) < 0.0000001 );
310});
311
312test( "lerp/clone", function() {
313	var a = new THREE.Vector3( x, 0, z );
314	var b = new THREE.Vector3( 0, -y, 0 );
315
316	ok( a.lerp( a, 0 ).equals( a.lerp( a, 0.5 ) ), "Passed!" );
317	ok( a.lerp( a, 0 ).equals( a.lerp( a, 1 ) ), "Passed!" );
318
319	ok( a.clone().lerp( b, 0 ).equals( a ), "Passed!" );
320
321	ok( a.clone().lerp( b, 0.5 ).x == x*0.5, "Passed!" );
322	ok( a.clone().lerp( b, 0.5 ).y == -y*0.5, "Passed!" );
323	ok( a.clone().lerp( b, 0.5 ).z == z*0.5, "Passed!" );
324
325	ok( a.clone().lerp( b, 1 ).equals( b ), "Passed!" );
326});
327
328test( "equals", function() {
329	var a = new THREE.Vector3( x, 0, z );
330	var b = new THREE.Vector3( 0, -y, 0 );
331
332	ok( a.x != b.x, "Passed!" );
333	ok( a.y != b.y, "Passed!" );
334	ok( a.z != b.z, "Passed!" );
335
336	ok( ! a.equals( b ), "Passed!" );
337	ok( ! b.equals( a ), "Passed!" );
338
339	a.copy( b );
340	ok( a.x == b.x, "Passed!" );
341	ok( a.y == b.y, "Passed!" );
342	ok( a.z == b.z, "Passed!" );
343
344	ok( a.equals( b ), "Passed!" );
345	ok( b.equals( a ), "Passed!" );
346});
347
Full Screen

Accelerate Your Automation Test Cycles With LambdaTest

Leverage LambdaTest’s cloud-based platform to execute your automation tests in parallel and trim down your test execution time significantly. Your first 100 automation testing minutes are on us.

Try LambdaTest

Run JavaScript Tests on LambdaTest Cloud Grid

Execute automation tests with Puppeteer on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.

Test now for Free
LambdaTestX

We use cookies to give you the best experience. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. Learn More in our Cookies policy, Privacy & Terms of service

Allow Cookie
Sarah

I hope you find the best code examples for your project.

If you want to accelerate automated browser testing, try LambdaTest. Your first 100 automation testing minutes are FREE.

Sarah Elson (Product & Growth Lead)