summaryrefslogtreecommitdiff
path: root/test/unit/proof/drat_proof_black.h
blob: 6fdb555933ddaf4dd5dde4f1368da5c1acb0a641 (plain)
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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*********************                                                        */
/*! \file drat_proof_black.h
 ** \verbatim
 ** Top contributors (to current version):
 **   Alex Ozdemir, Andres Noetzli
 ** This file is part of the CVC4 project.
 ** Copyright (c) 2009-2019 by the authors listed in the file AUTHORS
 ** in the top-level source directory) and their institutional affiliations.
 ** All rights reserved.  See the file COPYING in the top-level source
 ** directory for licensing information.\endverbatim
 **
 ** \brief Black box testing of the DRAT proof class
 **
 ** In particular, tests DRAT binary parsing.
 **/

#include <cxxtest/TestSuite.h>

#include <cctype>

#include "proof/drat/drat_proof.h"

using namespace CVC4::proof::drat;

class DratProofBlack : public CxxTest::TestSuite
{
 public:
  void setUp() override {}
  void tearDown() override {}

  void testParseOneAdd();
  void testParseOneMediumAdd();
  void testParseOneBigAdd();
  void testParseLiteralIsTooBig();
  void testParseLiteralOverflow();
  void testParseClauseOverflow();

  void testParseTwo();

  void testOutputTwoAsText();
  void testOutputTwoAsLfsc();
};

void DratProofBlack::testParseOneAdd()
{
  // a 1;
  std::string input("a\x02\x00", 3);
  DratProof proof = DratProof::fromBinary(input);

  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_kind, ADDITION);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause.size(), 1);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause[0],
                   SatLiteral(0, false));
}

void DratProofBlack::testParseOneMediumAdd()
{
  // a -255;
  std::string input("a\xff\x01\x00", 4);
  DratProof proof = DratProof::fromBinary(input);

  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_kind, ADDITION);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause.size(), 1);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause[0],
                   SatLiteral(126, true));
}

void DratProofBlack::testParseOneBigAdd()
{
  // a -2199023255551;
  std::string input("a\xff\xff\xff\xff\xff\x7f\x00", 8);
  DratProof proof = DratProof::fromBinary(input);

  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_kind, ADDITION);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause.size(), 1);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause[0],
                   SatLiteral(2199023255550, true));
}

void DratProofBlack::testParseLiteralIsTooBig()
{
  std::string input("a\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\xff\x7f\x00",
                    14);
  TS_ASSERT_THROWS(DratProof::fromBinary(input), InvalidDratProofException&);
}

void DratProofBlack::testParseLiteralOverflow()
{
  std::string input("a\x80", 2);
  TS_ASSERT_THROWS(DratProof::fromBinary(input), InvalidDratProofException&);
}

void DratProofBlack::testParseClauseOverflow()
{
  std::string input("a\x80\x01", 3);
  TS_ASSERT_THROWS(DratProof::fromBinary(input), InvalidDratProofException&);
}

void DratProofBlack::testParseTwo()
{
  // d -63 -8193
  // 129 -8191
  std::string input("\x64\x7f\x83\x80\x01\x00\x61\x82\x02\xff\x7f\x00", 12);
  DratProof proof = DratProof::fromBinary(input);

  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_kind, DELETION);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause.size(), 2);
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause[0],
                   SatLiteral(62, true));
  TS_ASSERT_EQUALS(proof.getInstructions()[0].d_clause[1],
                   SatLiteral(8192, true));

  TS_ASSERT_EQUALS(proof.getInstructions()[1].d_kind, ADDITION);
  TS_ASSERT_EQUALS(proof.getInstructions()[1].d_clause.size(), 2);
  TS_ASSERT_EQUALS(proof.getInstructions()[1].d_clause[0],
                   SatLiteral(128, false));
  TS_ASSERT_EQUALS(proof.getInstructions()[1].d_clause[1],
                   SatLiteral(8190, true));
}

void DratProofBlack::testOutputTwoAsText()
{
  // d -63 -8193
  // 129 -8191
  std::string input("\x64\x7f\x83\x80\x01\x00\x61\x82\x02\xff\x7f\x00", 12);
  DratProof proof = DratProof::fromBinary(input);

  std::ostringstream output;
  proof.outputAsText(output);

  std::istringstream tokens(output.str());
  std::string token;

  tokens >> token;
  TS_ASSERT_EQUALS(token, "d");

  tokens >> token;
  TS_ASSERT_EQUALS(token, "-63");

  tokens >> token;
  TS_ASSERT_EQUALS(token, "-8193");

  tokens >> token;
  TS_ASSERT_EQUALS(token, "0");

  tokens >> token;
  TS_ASSERT_EQUALS(token, "129");

  tokens >> token;
  TS_ASSERT_EQUALS(token, "-8191");

  tokens >> token;
  TS_ASSERT_EQUALS(token, "0");
}

void DratProofBlack::testOutputTwoAsLfsc()
{
  // d -63 -8193
  // 129 -8191
  std::string input("\x64\x7f\x83\x80\x01\x00\x61\x82\x02\xff\x7f\x00", 12);
  DratProof proof = DratProof::fromBinary(input);
  std::ostringstream lfsc;
  proof.outputAsLfsc(lfsc, 2);
  std::ostringstream lfscWithoutWhitespace;
  for (char c : lfsc.str())
  {
    if (!std::isspace(c))
    {
      lfscWithoutWhitespace << c;
    }
  }
  std::string expectedLfsc =
      "(DRATProofd (clc (neg bb.v62)  (clc (neg bb.v8192) cln))"
      "(DRATProofa (clc (pos bb.v128) (clc (neg bb.v8190) cln))"
      "DRATProofn))";
  std::ostringstream expectedLfscWithoutWhitespace;
  for (char c : expectedLfsc)
  {
    if (!std::isspace(c))
    {
      expectedLfscWithoutWhitespace << c;
    }
  }

  TS_ASSERT_EQUALS(lfscWithoutWhitespace.str(),
                   expectedLfscWithoutWhitespace.str());
}
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback