MCPcopy Create free account
hub / github.com/Z3Prover/z3 / castingTest

Method castingTest

examples/java/JavaExample.java:885–1029  ·  view source on GitHub ↗
(Context ctx)

Source from the content-addressed store, hash-verified

883 // / Some basic expression casting tests.
884
885 void castingTest(Context ctx) throws TestFailedException
886 {
887 System.out.println("CastingTest");
888
889 Sort[] domain = { ctx.getBoolSort(), ctx.getBoolSort() };
890 FuncDecl f = ctx.mkFuncDecl("f", domain, ctx.getBoolSort());
891
892 AST upcast = ctx.mkFuncDecl(ctx.mkSymbol("q"), domain,
893 ctx.getBoolSort());
894
895 try
896 {
897 @SuppressWarnings("unused")
898 FuncDecl downcast = (FuncDecl) f; // OK
899 } catch (ClassCastException e)
900 {
901 throw new TestFailedException();
902 }
903
904 try
905 {
906 @SuppressWarnings("unused")
907 Expr uc = (Expr) upcast;
908 throw new TestFailedException(); // should not be reachable!
909 } catch (ClassCastException e)
910 {
911 }
912
913 Symbol s = ctx.mkSymbol(42);
914 IntSymbol si = (s.getClass() == IntSymbol.class) ? (IntSymbol) s : null;
915 if (si == null)
916 throw new TestFailedException();
917 try
918 {
919 @SuppressWarnings("unused")
920 IntSymbol si2 = (IntSymbol) s;
921 } catch (ClassCastException e)
922 {
923 throw new TestFailedException();
924 }
925
926 s = ctx.mkSymbol("abc");
927 StringSymbol ss = (s.getClass() == StringSymbol.class) ? (StringSymbol) s
928 : null;
929 if (ss == null)
930 throw new TestFailedException();
931 try
932 {
933 @SuppressWarnings("unused")
934 StringSymbol ss2 = (StringSymbol) s;
935 } catch (ClassCastException e)
936 {
937 throw new TestFailedException();
938 }
939 try
940 {
941 @SuppressWarnings("unused")
942 IntSymbol si2 = (IntSymbol) s;

Callers 1

mainMethod · 0.95

Calls 13

getSizeMethod · 0.95
getArgsMethod · 0.95
getSortMethod · 0.95
getBoolSortMethod · 0.80
mkFuncDeclMethod · 0.80
mkSymbolMethod · 0.80
mkBitVecSortMethod · 0.80
mkAddMethod · 0.80
mkIntMethod · 0.80
mkTrueMethod · 0.80
mkFalseMethod · 0.80
mkNotMethod · 0.80

Tested by

no test coverage detected