|
| 1 | +#include <gtest/gtest.h> |
| 2 | + |
| 3 | +extern "C" |
| 4 | +{ |
| 5 | +#include "../../../INCHI-1-SRC/INCHI_BASE/src/inpdef.h" |
| 6 | +#include "../../../INCHI-1-SRC/INCHI_BASE/src/ichi_io.h" |
| 7 | +#include "../../../INCHI-1-SRC/INCHI_BASE/src/ichimain.h" |
| 8 | +#include "../../../INCHI-1-SRC/INCHI_BASE/src/permutation_util.h" |
| 9 | +} |
| 10 | + |
| 11 | +TEST(permutation_util_testing, test_OrigAtData_Permute) |
| 12 | +{ |
| 13 | + |
| 14 | + // 1. Populate atom data |
| 15 | + |
| 16 | + INCHI_IOSTREAM input_stream; |
| 17 | + const char *molblock = |
| 18 | + "\n" |
| 19 | + " InChIV10 \n" |
| 20 | + "\n" |
| 21 | + " 5 4 0 0 0 0 0 0 0 0 1 V2000\n" |
| 22 | + " 1.2124 0.0000 0.0000 O 0 0 0 0 0 0 0 0 0\n" |
| 23 | + " 2.4249 0.7000 0.0000 C 0 0 0 0 0 0 0 0 0\n" |
| 24 | + " 3.6373 0.0000 0.0000 C 0 0 0 0 0 0 0 0 0\n" |
| 25 | + " 2.4249 2.1000 0.0000 O 0 0 0 0 0 0 0 0 0\n" |
| 26 | + " 0.0000 0.7000 0.0000 Y 0 0 0 0 0 0 0 0 0\n" |
| 27 | + " 1 2 1 0 0 0 0\n" |
| 28 | + " 1 5 1 0 0 0 0\n" |
| 29 | + " 2 3 1 0 0 0 0\n" |
| 30 | + " 2 4 2 0 0 0 0\n" |
| 31 | + "M END\n" |
| 32 | + "$$$$\n"; |
| 33 | + inchi_ios_init(&input_stream, INCHI_IOS_TYPE_STRING, nullptr); |
| 34 | + inchi_ios_print_nodisplay(&input_stream, molblock); |
| 35 | + |
| 36 | + ORIG_ATOM_DATA atom_data{}; |
| 37 | + INCHI_MODE input_atom_flags = 0; |
| 38 | + int struct_read_error = 0; |
| 39 | + |
| 40 | + int num_atoms = 0; |
| 41 | + num_atoms = CreateOrigInpDataFromMolfile( |
| 42 | + &input_stream, |
| 43 | + &atom_data, |
| 44 | + 0, |
| 45 | + 0, |
| 46 | + 0, |
| 47 | + 0, |
| 48 | + 0, |
| 49 | + nullptr, |
| 50 | + nullptr, |
| 51 | + nullptr, |
| 52 | + nullptr, |
| 53 | + &input_atom_flags, |
| 54 | + &struct_read_error, |
| 55 | + nullptr, |
| 56 | + 0); |
| 57 | + |
| 58 | + ASSERT_EQ(num_atoms, 5); |
| 59 | + |
| 60 | + // 2. Permute atom indices |
| 61 | + |
| 62 | + ORIG_ATOM_DATA permuted_atom_data{}; |
| 63 | + |
| 64 | + int duplication_failed = 0; |
| 65 | + duplication_failed = OrigAtData_Duplicate(&permuted_atom_data, &atom_data); |
| 66 | + |
| 67 | + int permutation_mapping[num_atoms]; |
| 68 | + for (int i = 0; i < num_atoms; i++) |
| 69 | + { |
| 70 | + permutation_mapping[i] = i; |
| 71 | + } |
| 72 | + shuffle((void *)permutation_mapping, num_atoms, sizeof(int)); |
| 73 | + OrigAtData_Permute(&permuted_atom_data, &atom_data, permutation_mapping); |
| 74 | + |
| 75 | + // 3. Write molfile with permuted atom indices |
| 76 | + |
| 77 | + INCHI_IOSTREAM output_stream{}, permuted_output_stream{}; |
| 78 | + inchi_ios_init(&output_stream, INCHI_IOS_TYPE_STRING, nullptr); |
| 79 | + inchi_ios_init(&permuted_output_stream, INCHI_IOS_TYPE_STRING, nullptr); |
| 80 | + |
| 81 | + int return_code = 0; |
| 82 | + return_code = OrigAtData_WriteToSDfile( |
| 83 | + &atom_data, |
| 84 | + &output_stream, |
| 85 | + nullptr, |
| 86 | + nullptr, |
| 87 | + 0, |
| 88 | + 0, |
| 89 | + nullptr, |
| 90 | + nullptr); |
| 91 | + return_code = OrigAtData_WriteToSDfile( |
| 92 | + &permuted_atom_data, |
| 93 | + &permuted_output_stream, |
| 94 | + nullptr, |
| 95 | + nullptr, |
| 96 | + 0, |
| 97 | + 0, |
| 98 | + nullptr, |
| 99 | + nullptr); |
| 100 | + |
| 101 | + INCHI_IOSTREAM *output_file = &output_stream; |
| 102 | + INCHI_IOSTREAM *permuted_output_file = &permuted_output_stream; |
| 103 | + |
| 104 | + printf("Initial molblock:\n%s\n", molblock); |
| 105 | + printf("Initial molfile:\n%s\n", output_file->s.pStr); |
| 106 | + printf("Permuted molfile:\n%s\n", permuted_output_file->s.pStr); |
| 107 | + |
| 108 | + EXPECT_STREQ(molblock, output_file->s.pStr); |
| 109 | + EXPECT_STRNE(output_file->s.pStr, permuted_output_file->s.pStr); |
| 110 | +} |
0 commit comments