#!/bin/sh
# Copyright (C) 2012, 2014 Laboratoire de Recherche et Développement
# de l'Epita (LRDE).
#
# This file is part of Spot, a model checking library.
#
# Spot is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# Spot is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
# or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
# License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

. ./defs
set -e

# GNU systems have seq,
# BSD systems have jot.
# Neither of those are POSIX...
if test "*`(seq 1 1 2>/dev/null)`" = "1"; then
  have_seq=true
else
  have_seq=false
  if test "`(jot 1 1 2>/dev/null)`" = "1"; then
    have_jot=true
  else
    have_jot=false
  fi
fi

# enum start end
enum() {
  if $have_seq; then
    seq $1 $2
  elif $have_jot; then
    jot `expr $2 - $1 + 1` $1
  else
    i=$1
    while test $i -le $2; do
      echo $i
      i=`expr $i + 1`
    done
  fi
}

# Fig.1 from Johnson's SIAM J. Comput. 1975 paper.

(
echo 'acc = ;'
k=3
v=`expr $k + 2`
w=`expr 2 \* $k + 2`
x=`expr 3 \* $k + 3`
for i in $(enum 2 `expr $k + 1`); do
  echo "s1,s$i,,;"
  echo "s$i,s$v,,;"
done
for i in $(enum `expr $k + 2` `expr 2 \* $k`); do
  echo "s$i,s`expr $i + 1`,,;"
  echo "s$i,s$w,,;"
done
echo "s`expr 2 \* $k + 1`,s$w,,;"
echo "s`expr 2 \* $k + 1`,s1,,;"
for i in $(enum `expr 2 \* $k + 3` `expr 3 \* $k + 2`); do
  echo "s$w,s$i,,;"
  echo "s$i,s$x,,;"
done
echo "s`expr 2 \* $k + 3`,s$v,,;"
echo "s$x,s$w,,;"
) > johnson-fig1.tgba


run 0 ../ltl2tgba -KC -X johnson-fig1.tgba > out
test `wc -l < out` -eq 10

run 0 ../ltl2tgba -KW '(Ga -> Gb) W c' > out
test `grep 'is weak' out | wc -l` -eq 4
test `grep 'is not weak' out | wc -l` -eq 1
