File: concretize_array.cpp

package info (click to toggle)
cbmc 6.6.0-4
  • links: PTS
  • area: main
  • in suites: forky, sid, trixie
  • size: 153,852 kB
  • sloc: cpp: 386,459; ansic: 114,466; java: 28,405; python: 6,003; yacc: 4,552; makefile: 4,041; lex: 2,487; xml: 2,388; sh: 2,050; perl: 557; pascal: 184; javascript: 163; ada: 36
file content (56 lines) | stat: -rw-r--r-- 1,843 bytes parent folder | download
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
/*******************************************************************\

Module: Unit tests for interval_sparse_arrayt::concretize in
        solvers/refinement/string_refinement_util.cpp

Author: Diffblue Ltd.

\*******************************************************************/

#include <testing-utils/use_catch.h>

#include <util/arith_tools.h>
#include <util/std_expr.h>

#include <solvers/strings/string_refinement_util.h>

SCENARIO(
  "concretize_array_expression",
  "[core][solvers][strings][string_refinement]")
{
  // Arrange
  const typet char_type = unsignedbv_typet(16);
  const typet int_type = signedbv_typet(32);
  const exprt index1 = from_integer(1, int_type);
  const exprt charx = from_integer('x', char_type);
  const exprt index4 = from_integer(4, int_type);
  const exprt chary = from_integer('y', char_type);
  const exprt index100 = from_integer(100, int_type);
  const exprt char0 = from_integer('0', char_type);
  const exprt index2 = from_integer(2, int_type);
  const exprt charz = from_integer('z', char_type);
  array_typet array_type(char_type, infinity_exprt(int_type));

  // input_expr is
  // ARRAY_OF(0) WITH [1:=x] WITH [4:=y] WITH [100:=z]`
  const with_exprt input_expr(
    with_exprt(
      with_exprt(
        array_of_exprt(from_integer(0, char_type), array_type), index1, charx),
      index4,
      chary),
    index100,
    charz);

  // Act
  const interval_sparse_arrayt sparse_array(input_expr);
  // String size is 7, so index 100 should get ignored.
  const exprt concrete = sparse_array.concretize(7, int_type);

  // Assert
  // The expected result is `{ 'x', 'x', 'y', 'y', 'y', 'z', 'z' }`
  array_exprt expected(
    {charx, charx, chary, chary, chary, charz, charz}, array_type);
  to_array_type(expected.type()).size() = from_integer(7, int_type);
  REQUIRE(concrete == expected);
}