-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.php
More file actions
62 lines (51 loc) · 1.04 KB
/
test.php
File metadata and controls
62 lines (51 loc) · 1.04 KB
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
<?php
use FloFaber\Bencode\Bencode;
require_once("Bencode.php");
function pass(){
echo ": Passed\n";
}
function fail($msg = ""){
echo ": Failed ($msg)\n";
}
// @ToDo: Decoding Tests
echo "Encoding string: ";
try{
if(Bencode::encode("This is a string") === "16:This is a string"){
pass();
}else{
fail();
}
}catch (Exception $e){
fail($e->getMessage());
}
echo "Encoding integer: ";
try{
if(Bencode::encode(1337) === "i1337e"){
pass();
}else{
fail();
}
}catch (Exception $e){
fail($e->getMessage());
}
echo "Encoding list: ";
try{
if(Bencode::encode([ "beetlejuice", "beetlejuice", "beetlejuice" ]) === "l11:beetlejuice11:beetlejuice11:beetlejuicee"){
pass();
}else{
fail();
}
}catch (Exception $e){
fail($e->getMessage());
}
echo "Encoding dictionary: ";
try{
if(Bencode::encode([ "pear" => "tracker", "banana" => "papaya", "apple" => "google" ]) === "d4:pear7:tracker6:banana6:papaya5:apple6:googlee"){
pass();
}else{
fail();
}
}catch (Exception $e){
fail($e->getMessage());
}
echo "\n";