Overview
Comment: | smaz-tests: add a basic Smaz test, using simple common strings |
---|---|
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA1: |
eee21b3a8c4b77e5814982bc4086ba3c |
User & Date: | nat on 2016-09-13 20:27:10 |
Other Links: | manifest | tags |
Context
2016-09-14
| ||
21:44 |
smaz-tests: make round-trip test really a round-trip
Since there are multiple encoded sequence that decompress into the same original string, it is much more important to check that compressed data really decompress into the original data than to check that it matches exactly the expected byte sequence check-in: e2fbcb314b user: nat tags: trunk | |
2016-09-13
| ||
20:27 | smaz-tests: add a basic Smaz test, using simple common strings check-in: eee21b3a8c user: nat tags: trunk | |
2016-09-12
| ||
21:10 | smaz-original: new package providing the original Smaz dictionary check-in: 59ee9e9566 user: nat tags: trunk | |
Changes
Added tests/natools-smaz-tests.adb version [03fb241432].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | ------------------------------------------------------------------------------ -- Copyright (c) 2015-2016, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ with Ada.Strings.Unbounded; with Natools.Smaz.Original; package body Natools.Smaz.Tests is function Image (S : Ada.Streams.Stream_Element_Array) return String; procedure Roundtrip_Test (Test : in out NT.Test; Dict : in Dictionary; Decompressed : in String; Compressed : in Ada.Streams.Stream_Element_Array); ------------------------------ -- Local Helper Subprograms -- ------------------------------ function Image (S : Ada.Streams.Stream_Element_Array) return String is use Ada.Strings.Unbounded; Result : Unbounded_String; begin for I in S'Range loop Append (Result, Ada.Streams.Stream_Element'Image (S (I))); end loop; return To_String (Result); end Image; procedure Roundtrip_Test (Test : in out NT.Test; Dict : in Dictionary; Decompressed : in String; Compressed : in Ada.Streams.Stream_Element_Array) is use type Ada.Streams.Stream_Element_Array; use type Ada.Streams.Stream_Element_Offset; Buffer : Ada.Streams.Stream_Element_Array (1 .. Compressed_Upper_Bound (Dict, Decompressed) + 10); Last : Ada.Streams.Stream_Element_Offset; Done : Boolean := False; begin begin Compress (Dict, Decompressed, Buffer, Last); Done := True; exception when Error : others => Test.Info ("During compression of """ & Decompressed & '"'); Test.Report_Exception (Error, NT.Fail); end; if Done and then Buffer (1 .. Last) /= Compressed then Test.Fail ("Compression of """ & Decompressed & """ failed"); Test.Info ("Found: " & Image (Buffer (1 .. Last))); Test.Info ("Expected:" & Image (Compressed)); end if; declare Buffer_2 : String (1 .. Decompressed_Length (Dict, Buffer (1 .. Last))); Last_2 : Natural; Done : Boolean := False; begin begin Decompress (Dict, Compressed, Buffer_2, Last_2); Done := True; exception when Error : others => Test.Info ("During compression of """ & Decompressed & '"'); Test.Report_Exception (Error, NT.Fail); end; if Done and then Buffer_2 (1 .. Last_2) /= Decompressed then Test.Fail ("Roundtrip for """ & Decompressed & """ failed"); Test.Info ("Found """ & Buffer_2 (1 .. Last_2) & '"'); end if; end; end Roundtrip_Test; ------------------------- -- Complete Test Suite -- ------------------------- procedure All_Tests (Report : in out NT.Reporter'Class) is begin Sample_Strings (Report); end All_Tests; ---------------------- -- Individual Tests -- ---------------------- procedure Sample_Strings (Report : in out NT.Reporter'Class) is Test : NT.Test := Report.Item ("Roundtrip on sample strings"); begin Roundtrip_Test (Test, Original.Dictionary, "This is a small string", (254, 84, 76, 56, 172, 62, 173, 152, 62, 195, 70)); Roundtrip_Test (Test, Original.Dictionary, "foobar", (220, 6, 90, 79)); Roundtrip_Test (Test, Original.Dictionary, "the end", (1, 171, 61)); Roundtrip_Test (Test, Original.Dictionary, "not-a-g00d-Exampl333", (132, 204, 4, 204, 59, 255, 1, 48, 48, 24, 204, 254, 69, 250, 4, 45, 60, 22, 255, 2, 51, 51, 51)); Roundtrip_Test (Test, Original.Dictionary, "Smaz is a simple compression library", (254, 83, 173, 219, 56, 172, 62, 226, 60, 87, 161, 45, 60, 33, 166, 107, 205, 8, 90, 130, 12, 83)); Roundtrip_Test (Test, Original.Dictionary, "Nothing is more difficult, and therefore more precious, " & "than to be able to decide", (254, 78, 223, 102, 99, 116, 45, 42, 11, 129, 44, 44, 131, 38, 22, 3, 148, 63, 210, 68, 11, 45, 42, 11, 60, 33, 28, 144, 164, 36, 203, 143, 96, 92, 25, 90, 87, 82, 165, 215, 237, 2)); Roundtrip_Test (Test, Original.Dictionary, "this is an example of what works very well with smaz", (155, 56, 172, 41, 2, 250, 4, 45, 60, 87, 32, 159, 135, 65, 42, 254, 107, 23, 231, 71, 145, 152, 243, 227, 10, 173, 219)); Roundtrip_Test (Test, Original.Dictionary, "1000 numbers 2000 will 10 20 30 compress very little", (255, 3, 49, 48, 48, 48, 236, 38, 45, 92, 221, 0, 255, 3, 50, 48, 48, 48, 243, 152, 0, 255, 1, 49, 48, 0, 255, 1, 50, 48, 0, 255, 1, 51, 48, 161, 45, 60, 33, 166, 0, 231, 71, 151, 3, 3, 87)); exception when Error : others => Test.Report_Exception (Error); end Sample_Strings; end Natools.Smaz.Tests; |
Added tests/natools-smaz-tests.ads version [5b00cffab8].
> > > > > > > > > > > > > > > > > > > > > > > > > > > | 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 | ------------------------------------------------------------------------------ -- Copyright (c) 2016, Natacha Porté -- -- -- -- Permission to use, copy, modify, and distribute this software for any -- -- purpose with or without fee is hereby granted, provided that the above -- -- copyright notice and this permission notice appear in all copies. -- -- -- -- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES -- -- WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF -- -- MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR -- -- ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES -- -- WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN -- -- ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF -- -- OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. -- ------------------------------------------------------------------------------ with Natools.Tests; package Natools.Smaz.Tests is package NT renames Natools.Tests; procedure All_Tests (Report : in out NT.Reporter'Class); procedure Sample_Strings (Report : in out NT.Reporter'Class); end Natools.Smaz.Tests; |
Modified tests/test_all.adb from [c6f080431e] to [4cf3530b46].
︙ | ︙ | |||
37 38 39 40 41 42 43 44 45 46 47 48 49 50 | with Natools.S_Expressions.Interpreter_Tests; with Natools.S_Expressions.Lockable.Tests; with Natools.S_Expressions.Parsers.Tests; with Natools.S_Expressions.Printers.Tests; with Natools.S_Expressions.Printers.Pretty.Tests; with Natools.S_Expressions.Printers.Pretty.Config.Tests; with Natools.S_Expressions.Templates.Tests; with Natools.Static_Hash_Maps.S_Expressions.Tests; with Natools.String_Slice_Set_Tests; with Natools.String_Slice_Tests; with Natools.Time_IO.Tests; with Natools.Time_Keys.Tests; with Natools.Time_Statistics.Tests; with Natools.Tests.Text_IO; | > | 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | with Natools.S_Expressions.Interpreter_Tests; with Natools.S_Expressions.Lockable.Tests; with Natools.S_Expressions.Parsers.Tests; with Natools.S_Expressions.Printers.Tests; with Natools.S_Expressions.Printers.Pretty.Tests; with Natools.S_Expressions.Printers.Pretty.Config.Tests; with Natools.S_Expressions.Templates.Tests; with Natools.Smaz.Tests; with Natools.Static_Hash_Maps.S_Expressions.Tests; with Natools.String_Slice_Set_Tests; with Natools.String_Slice_Tests; with Natools.Time_IO.Tests; with Natools.Time_Keys.Tests; with Natools.Time_Statistics.Tests; with Natools.Tests.Text_IO; |
︙ | ︙ | |||
158 159 160 161 162 163 164 165 166 167 168 169 170 171 | Report.Section ("S_Expressions.Printers.Pretty.Config"); Natools.S_Expressions.Printers.Pretty.Config.Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Templates"); Natools.S_Expressions.Templates.Tests.All_Tests (Report); Report.End_Section; Report.Section ("Static_Hash_Maps.S_Expressions"); Natools.Static_Hash_Maps.S_Expressions.Tests.All_Tests (Report); Report.End_Section; Report.Section ("String_Slices"); Natools.String_Slice_Tests.All_Tests (Report); | > > > > | 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 | Report.Section ("S_Expressions.Printers.Pretty.Config"); Natools.S_Expressions.Printers.Pretty.Config.Tests.All_Tests (Report); Report.End_Section; Report.Section ("S_Expressions.Templates"); Natools.S_Expressions.Templates.Tests.All_Tests (Report); Report.End_Section; Report.Section ("Smaz"); Natools.Smaz.Tests.All_Tests (Report); Report.End_Section; Report.Section ("Static_Hash_Maps.S_Expressions"); Natools.Static_Hash_Maps.S_Expressions.Tests.All_Tests (Report); Report.End_Section; Report.Section ("String_Slices"); Natools.String_Slice_Tests.All_Tests (Report); |
︙ | ︙ |