Debian Codegraph @

swig/perl5/t/test_hash_counter.t

raw
1 # This file is part of Jellyfish.
2 #
3 # This work is dual-licensed under 3-Clause BSD License or GPL 3.0.
4 # You can choose between one of them if you use this work.
5 #
6 # `SPDX-License-Identifier: BSD-3-Clause OR GPL-3.0`
7
8 use strict;
9 use warnings;
10 use Test::More;
11 use jellyfish;
12
13 require_ok('jellyfish');
14 my $data = shift(@ARGV);
15
16 jellyfish::MerDNA::k(100);
17 my $hash = jellyfish::HashCounter->new(1024, 5);
18
19 # Check info
20 ok(100 == jellyfish::MerDNA::k, "mer_dna k");
21 ok(1024 == $hash->size, "Hash size");
22 ok(5 == $hash->val_len, "Hash value length");
23
24 # Test adding mers
25 {
26 my $mer = jellyfish::MerDNA->new;
27 my $good = 1;
28 for(my $i = 0; $i < 1000; $i++) {
29 $mer->randomize();
30 my $val = int(rand(1000));
31 $good &&= $hash->add($mer, $val) or
32 (ok($good, "Adding to new mer") || last);
33 if($i % 3 > 0) {
34 my $nval = int(rand(1000));
35 $val += $nval;
36 if($i % 3 == 1) {
37 $good &&= !$hash->add($mer, $nval) or
38 (ok($good, "Adding to existing mer") || last);
39 } else {
40 $good &&= $hash->update_add($mer, $nval) or
41 (ok($good, "Updating existing mer") || last);
42 }
43 }
44 $good &&= $val == $hash->get($mer) or
45 (ok($good, "Value in hash") || last);
46
47 }
48 ok($good, "Adding mer to hash");
49 }
50
51 done_testing;