예제 #1
0
파일: tgf.go 프로젝트: th0br0/carneades-4
func Import(inFile io.Reader) (af dung.AF, err error) {
	reader := bufio.NewReader(inFile)
	args := make([]dung.Arg, 0, 50)
	atks := make(map[dung.Arg][]dung.Arg, 50)
	nodeList := true // false if reading the list of edges has begun
	var line, token1, token2 string
	var n int
	eof := false
	for !eof {
		token1, token2 = "", ""
		line, err = reader.ReadString('\n')
		if err == io.EOF {
			err = nil // io.EOF isn't really an error
			eof = true
		} else if err != nil {
			return af, err // finish immediately for real errors
		}
		n, _ = fmt.Sscan(line, &token1, &token2)
		if nodeList && n >= 1 {
			if token1 == "#" {
				nodeList = false // start of edges list
				continue
			}
			args = append(args, dung.Arg(token1))
		} else if !nodeList && n >= 2 { // edges list
			atks[dung.Arg(token2)] = append(atks[dung.Arg(token2)], dung.Arg(token1))
		} else {
			continue // skip empty and invalid lines
		}
	}
	return dung.NewAF(args, atks), err
}
예제 #2
0
func TestUnattackedArg(t *testing.T) {
	af := dung.NewAF([]dung.Arg{a1},
		map[dung.Arg][]dung.Arg{})
	l := af.GroundedExtension()
	expected := true
	actual := l.Contains(a1)
	if actual != expected {
		t.Errorf("expected extension to contain 1")
	}
}
예제 #3
0
func TestSelfAttack(t *testing.T) {
	args := []dung.Arg{a1}
	atks := make(map[dung.Arg][]dung.Arg)
	atks[a1] = []dung.Arg{a1}
	af := dung.NewAF(args, atks)
	l := af.GroundedExtension()
	expected := false
	actual := l.Contains(a1)
	if actual != expected {
		t.Errorf("expected extension to not contain 1")
	}
}
예제 #4
0
func TestAttackedArg(t *testing.T) {
	args := []dung.Arg{a1, a2}
	atks := make(map[dung.Arg][]dung.Arg)
	atks[a1] = []dung.Arg{a2}
	af := dung.NewAF(args, atks)
	l := af.GroundedExtension()
	if l.Contains(a1) {
		t.Errorf("expected 1 to be out")
	}
	if !l.Contains(a2) {
		t.Errorf("expected 2 to be in")
	}
}
예제 #5
0
func TestAf2Import(t *testing.T) {
	inFile, err := os.Open("AFs/reinstatement1.tgf")
	if err != nil {
		log.Fatal(err)
	}
	af, err := tgf.Import(inFile)
	args := []dung.Arg{a1, a2, a3}
	atks := make(map[dung.Arg][]dung.Arg)
	atks[a2] = []dung.Arg{a1}
	atks[a3] = []dung.Arg{a2}
	expected := dung.NewAF(args, atks)
	if !af.Equals(expected) {
		t.Errorf("expected %s, not %s.\n", expected.String(), af.String())
	}
}