1 /*===========================================================================
2 *
3 * PUBLIC DOMAIN NOTICE
4 * National Center for Biotechnology Information
5 *
6 * This software/database is a "United States Government Work" under the
7 * terms of the United States Copyright Act. It was written as part of
8 * the author's official duties as a United States Government employee and
9 * thus cannot be copyrighted. This software/database is freely available
10 * to the public for use. The National Library of Medicine and the U.S.
11 * Government have not placed any restriction on its use or reproduction.
12 *
13 * Although all reasonable efforts have been taken to ensure the accuracy
14 * and reliability of the software and data, the NLM and the U.S.
15 * Government do not and cannot warrant the performance or results that
16 * may be obtained by using this software or data. The NLM and the U.S.
17 * Government disclaim all warranties, express or implied, including
18 * warranties of performance, merchantability or fitness for any particular
19 * purpose.
20 *
21 * Please cite the author in any work or product based on this material.
22 *
23 * ===========================================================================
24 *
25 */
26
27 #include "../../tools/sra-stat/assembly-statistics.c" /* Contigs */
28
29 #include <ktst/unit_test.hpp> // TEST_SUITE
30
31 TEST_SUITE ( TestAssemblyStatistics );
32
TEST_CASE(empty)33 TEST_CASE ( empty ) {
34 Contigs empty;
35 memset ( & empty, 0, sizeof empty );
36
37 Contigs contigs;
38 ContigsInit ( & contigs );
39
40 REQUIRE_EQ ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
41
42 ContigsCalculateStatistics ( & contigs );
43 REQUIRE_EQ ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
44
45 ContigsFini ( & contigs );
46 REQUIRE_EQ ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
47 }
48
Add(Contigs * contigs)49 static rc_t Add ( Contigs * contigs ) {
50 rc_t rc = ContigsAdd ( contigs, 70 );
51
52 rc_t r2 = ContigsAdd ( contigs, 80 );
53 if ( rc == 0 )
54 rc = r2;
55
56 r2 = ContigsAdd ( contigs, 20 );
57 if ( rc == 0 )
58 rc = r2;
59
60 r2 = ContigsAdd ( contigs, 50 );
61 if ( rc == 0 )
62 rc = r2;
63
64 r2 = ContigsAdd ( contigs, 30 );
65 if ( rc == 0 )
66 rc = r2;
67
68 r2 = ContigsAdd ( contigs, 40);
69 if ( rc == 0 )
70 rc = r2;
71
72 return rc;
73 }
74
75 ////////////////////////////////////////////////////////////////////////////////
76 static const uint64_t ZERO = 0;
77
78 /* examples from https://en.wikipedia.org/wiki/N50,_L50,_and_related_statistics
79 */
TEST_CASE(test5)80 TEST_CASE ( test5 ) {
81
82 Contigs empty;
83 memset ( & empty, 0, sizeof empty );
84
85 Contigs contigs;
86 ContigsInit ( & contigs );
87 REQUIRE_EQ ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
88 REQUIRE_EQ ( contigs . assemblyLength, ZERO );
89 REQUIRE_EQ ( contigs . contigLength, ZERO );
90
91 REQUIRE_RC ( Add ( & contigs ) );
92
93 REQUIRE_NE ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
94
95 REQUIRE_EQ ( contigs . assemblyLength, static_cast <uint64_t> ( 290 ) );
96 REQUIRE_EQ ( contigs . contigLength, static_cast <uint64_t> ( 6 ) );
97
98 ContigsCalculateStatistics ( & contigs );
99
100 REQUIRE_EQ ( contigs . assemblyLength, static_cast <uint64_t> ( 290 ) );
101 REQUIRE_EQ ( contigs . contigLength, static_cast <uint64_t> ( 6 ) );
102 REQUIRE_EQ ( contigs . n50, static_cast <uint64_t> ( 70 ) );
103 REQUIRE_EQ ( contigs . l50, static_cast <uint64_t> ( 2 ) );
104 REQUIRE_EQ ( contigs . n90, static_cast <uint64_t> ( 30 ) );
105 REQUIRE_EQ ( contigs . l90, static_cast <uint64_t> ( 5 ) );
106
107 REQUIRE_NE ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
108
109 ContigsFini ( & contigs );
110 REQUIRE_NE ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
111 }
112
TEST_CASE(test7)113 TEST_CASE ( test7 ) {
114 Contigs empty;
115 memset ( & empty, 0, sizeof empty );
116
117 Contigs contigs;
118 ContigsInit ( & contigs );
119 REQUIRE_EQ ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
120 REQUIRE_EQ ( contigs . assemblyLength, ZERO );
121 REQUIRE_EQ ( contigs . contigLength, ZERO );
122
123 REQUIRE_RC ( Add ( & contigs ) );
124 REQUIRE_RC ( ContigsAdd ( & contigs, 5 ) );
125 REQUIRE_RC ( ContigsAdd ( & contigs, 10 ) );
126
127 REQUIRE_NE ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
128
129 REQUIRE_EQ ( contigs . assemblyLength, static_cast <uint64_t> ( 305 ) );
130 REQUIRE_EQ ( contigs . contigLength, static_cast <uint64_t> ( 8 ) );
131
132 ContigsCalculateStatistics ( & contigs );
133
134 REQUIRE_EQ ( contigs . assemblyLength, static_cast <uint64_t> ( 305 ) );
135 REQUIRE_EQ ( contigs . contigLength, static_cast <uint64_t> ( 8 ) );
136 REQUIRE_EQ ( contigs . n50, static_cast <uint64_t> ( 50 ) );
137 REQUIRE_EQ ( contigs . l50, static_cast <uint64_t> ( 3 ) );
138 REQUIRE_EQ ( contigs . n90, static_cast <uint64_t> ( 20 ) );
139 REQUIRE_EQ ( contigs . l90, static_cast <uint64_t> ( 6 ) );
140
141 REQUIRE_NE ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
142
143 ContigsFini ( & contigs );
144 REQUIRE_NE ( memcmp ( & contigs, & empty, sizeof empty ), 0 );
145 }
146
147 extern "C" {
KAppVersion(void)148 ver_t CC KAppVersion ( void ) { return 0; }
KMain(int argc,char * argv[])149 rc_t CC KMain ( int argc, char * argv [] ) {
150 return TestAssemblyStatistics ( argc, argv );
151 }
152 }
153