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 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169
|
#!/usr/bin/perl
use warnings;
use strict;
use Test::More tests => 27;
use Test::Bot::BasicBot::Pluggable;
my $bot = Test::Bot::BasicBot::Pluggable->new();
my $karma = $bot->load('Karma');
## We start testing without giving any reasons
$karma->set( "user_num_comments", 0 );
is(
$bot->tell_indirect('karma alice'),
'alice has karma of 0.',
'inital karma of alice'
);
is(
$bot->tell_indirect('explain karma alice'),
'positive: 0; negative: 0; overall: 0.',
'explain initial karma of alice'
);
$bot->tell_indirect('alice--');
is(
$bot->tell_indirect('karma alice'),
'alice has karma of -1.',
'karma of alice after first --'
);
$bot->tell_indirect('alice++');
$bot->tell_indirect('alice++');
is(
$bot->tell_indirect('karma alice'),
'alice has karma of 1.',
'karma of alice after first ++'
);
$bot->tell_indirect('alice++');
is(
$bot->tell_indirect('karma alice'),
'alice has karma of 2.',
'karma of alice after second ++'
);
is(
$bot->tell_indirect('explain karma alice'),
'positive: 3; negative: 1; overall: 2.',
'explain karma of Alice'
);
is( $bot->tell_indirect('test_bot++'),
'Karma for test_bot is now 1 (thanks!)', 'thanking for karming up bot' );
is( $bot->tell_indirect( 'test_bot--', 'alice' ),
'Karma for test_bot is now 0 (pffft)', 'complaining about karming down bot' );
$bot->tell_indirect('test_user++');
test_karma( 'test_user', 0, 'user is not allowed to use positiv selfkarma' );
$bot->tell_indirect('test_user--');
test_karma( 'test_user', 0, 'user is not allowed to use negative selfkarma' );
$karma->set( 'user_ignore_selfkarma', 0 );
$bot->tell_indirect('test_user++');
test_karma( 'test_user', 1, 'user is allowed to use positive selfkarma' );
$bot->tell_indirect('test_user--');
test_karma( 'test_user', 0, 'user is allowed to use negativ selfkarma' );
is(
$karma->help(),
'Gives karma for or against a particular thing. Usage: <thing>++ # comment, <thing>-- # comment, karma <thing>, explain <thing>.',
'help for karma'
);
is(
$bot->tell_indirect('karma'),
'test_user has karma of 0.',
'asking for own karma without arguments'
);
is( $bot->tell_indirect( 'foobar', 'alice' ),
'', 'ignoring karma unrelated issues' );
$bot->tell_indirect('(alice code)--');
is(
$bot->tell_indirect('karma alice code'),
'alice code has karma of -1.',
'decrease karma of things with spaces '
);
$bot->tell_indirect('(alice code)++');
is(
$bot->tell_indirect('karma alice code'),
'alice code has karma of 0.',
'increasing karma of things with spaces '
);
$bot->tell_indirect('alice: ++');
is(
$bot->tell_indirect('karma alice'),
'alice has karma of 2.',
'positiv karma in sentance'
);
is( $bot->tell_indirect( 'explain', '' ),
'', 'ignore explain without argument' );
is( $bot->tell_indirect('++'), '', 'ignoring ++ without thing or address' );
is( $bot->tell_indirect('--'), '', 'ignoring -- without thing or address' );
## Now we start testing reasons
$karma->set( "user_num_comments", 2 );
$karma->set( "user_show_givers", 0 );
$karma->set( "user_randomize_reasons", 0 );
$bot->tell_indirect('alice++ # good cipher');
is(
$bot->tell_indirect('explain alice'),
'positive: good cipher; negative: nothing; overall: 3.',
'explaining karma of alice with one positive reason'
);
$bot->tell_indirect('alice-- # bad cipher');
is(
$bot->tell_indirect('explain alice'),
'positive: good cipher; negative: bad cipher; overall: 2.',
'explaining karma of alice with one positive and negative reason'
);
$bot->tell_indirect('alice-- # Friend of Eve');
is(
$bot->tell_indirect('explain alice'),
'positive: good cipher; negative: Friend of Eve, bad cipher; overall: 1.',
'explaining karma of alice with one positive and two negative reason'
);
$bot->tell_indirect('alice-- # Friend of Mallory');
is(
$bot->tell_indirect('explain alice'),
'positive: good cipher; negative: Friend of Mallory, Friend of Eve; overall: 0.',
'explaining karma of alice with more than two reasons (user_num_commments=2)'
);
$karma->set( "user_show_givers", 1 );
is(
$bot->tell_indirect('explain alice'),
'positive: good cipher (test_user); negative: Friend of Mallory (test_user), Friend of Eve (test_user); overall: 0.',
'explaining karma of alice with reasons and givers'
);
$karma->set( "user_randomize_reasons", 1 );
{
my %explanations;
for ( 1 .. 100 ) {
$explanations{ $bot->tell_indirect('explain alice') }++;
}
is( keys %explanations, 6, 'Testing randomness of reason list... (uh!)' )
}
sub test_karma {
my ( $thing, $value, $message ) = @_;
is( $karma->get_karma($thing), $value, $message );
}
|