Eine aufbereitete Darstellung der Quelle

 
     
 
 
Anforderungen  |   Konzepte  |   Entwurf  |   Entwicklung  |   Qualitätssicherung  |   Lebenszyklus  |   Steuerung
 
 
 
 

Benutzer

Quelle  configurable_test.go   Sprache: unbekannt

 
Spracherkennung für: .go vermutete Sprache: Unknown {[0] [0] [0]} [Methode: Schwerpunktbildung, einfache Gewichte, sechs Dimensionen]

package proptools

import (
 "fmt"
 "reflect"
 "testing"
)

func TestPostProcessor(t *testing.T) {
 // Same as the ascii art example in Configurable.evaluate()
 prop := NewConfigurable[[]string](nil, nil)
 prop.AppendSimpleValue([]string{"a"})
 prop.AppendSimpleValue([]string{"b"})
 prop.AddPostProcessor(addToElementsProcessor{"1"})

 prop2 := NewConfigurable[[]string](nil, nil)
 prop2.AppendSimpleValue([]string{"c"})

 prop3 := NewConfigurable[[]string](nil, nil)
 prop3.AppendSimpleValue([]string{"d"})
 prop3.AppendSimpleValue([]string{"e"})
 prop3.AddPostProcessor(addToElementsProcessor{"2"})

 prop4 := NewConfigurable[[]string](nil, nil)
 prop4.AppendSimpleValue([]string{"f"})

 prop5 := NewConfigurable[[]string](nil, nil)
 prop5.AppendSimpleValue([]string{"g"})
 prop5.AddPostProcessor(addToElementsProcessor{"3"})

 prop2.Append(prop3)
 prop2.AddPostProcessor(addToElementsProcessor{"z"})

 prop.Append(prop2)
 prop.AddPostProcessor(addToElementsProcessor{"y"})
 prop.Append(prop4)
 prop.Append(prop5)

 expected := []string{"a1y", "b1y", "czy", "d2zy", "e2zy", "f", "g3"}
 x := prop.Get(&configurableEvalutorForTesting{})
 if !reflect.DeepEqual(x.Get(), expected) {
  t.Fatalf("Expected %v, got %v", expected, x.Get())
 }

 _, err := CalculateHashReflection(prop)
 if err != nil {
  t.Errorf("Error calculating hash of configurable after AddPostProcessor: %s", err.Error())
 }
}

func TestPostProcessorWhenPassedToHelperFunction(t *testing.T) {
 prop := NewConfigurable[[]string](nil, nil)
 prop.AppendSimpleValue([]string{"a"})
 prop.AppendSimpleValue([]string{"b"})

 helper := func(p Configurable[[]string]) {
  p.AddPostProcessor(addToElementsProcessor{"1"})
 }

 helper(prop)

 expected := []string{"a1", "b1"}
 x := prop.Get(&configurableEvalutorForTesting{})
 if !reflect.DeepEqual(x.Get(), expected) {
  t.Fatalf("Expected %v, got %v", expected, x.Get())
 }
}

type addToElementsProcessor struct {
 s string
}

func (p addToElementsProcessor) PostProcess(arr []string) []string {
 for i := range arr {
  arr[i] = arr[i] + p.s
 }
 return arr
}

type configurableEvalutorForTesting struct {
 vars map[string]string
}

func (e *configurableEvalutorForTesting) EvaluateConfiguration(condition ConfigurableCondition, property string) ConfigurableValue {
 if condition.functionName != "f" {
  panic("Expected functionName to be f")
 }
 if len(condition.args) != 1 {
  panic("Expected exactly 1 arg")
 }
 val, ok := e.vars[condition.args[0]]
 if ok {
  return ConfigurableValueString(val)
 }
 return ConfigurableValueUndefined()
}

func (e *configurableEvalutorForTesting) PropertyErrorf(property, fmtString string, args ...interface{}) {
 panic(fmt.Sprintf(fmtString, args...))
}

var _ ConfigurableEvaluator = (*configurableEvalutorForTesting)(nil)

[Dauer der Verarbeitung: 0.17 Sekunden, vorverarbeitet 2026-06-28]

                                                                                                                                                                                                                                                                                                                                                                                                     


Neuigkeiten

     Aktuelles
     Motto des Tages

Software

     Quellcodebibliothek
     Eigene Quellcodes
     Fremde Quellcodes
     Suchen

Aktivitäten

     Artikel über Sicherheit
     Anleitung zur Aktivierung von SSL

Muße

     Gedichte
     Musik
     Bilder

Jenseits des Üblichen ....
    

Besucherstatistik

Besucherstatistik