Quellcodebibliothek Statistik Leitseite products/Sources/formale Sprachen/C/Android/build/build/soong/ui/status/   (Android Betriebssystem Version 17©)  Datei vom 26.5.2026 mit Größe 3 kB image not shown  

Quelle  critical_path_test.go   Sprache: unbekannt

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

// Copyright 2019 Google Inc. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package status

import (
 "reflect"
 "testing"
 "time"
)

type testCriticalPath struct {
 *CriticalPath
 Counts

 actions map[int]*Action
}

type testClock time.Time

func (t testClock) Now() time.Time { return time.Time(t) }

func (t *testCriticalPath) start(id int, startTime time.Duration, outputs, inputs []string) {
 t.clock = testClock(time.Unix(00).Add(startTime))
 action := &Action{
  Description: outputs[0],
  Outputs:     outputs,
  Inputs:      inputs,
 }

 t.actions[id] = action
 t.StartAction(action)
}

func (t *testCriticalPath) finish(id int, endTime time.Duration) {
 t.clock = testClock(time.Unix(00).Add(endTime))
 t.FinishAction(t.actions[id])
}

func TestCriticalPath(t *testing.T) {
 tests := []struct {
  name     string
  msgs     func(*testCriticalPath)
  want     []string
  wantTime time.Duration
 }{
  {
   name: "empty",
   msgs: func(cp *testCriticalPath) {},
  },
  {
   name: "duplicate",
   msgs: func(cp *testCriticalPath) {
    cp.start(00, []string{"a"}, nil)
    cp.start(10, []string{"a"}, nil)
    cp.finish(01000)
    cp.finish(02000)
   },
   want:     []string{"a"},
   wantTime: 1000,
  },
  {
   name: "linear",
   //  a
   //  |
   //  b
   //  |
   //  c
   msgs: func(cp *testCriticalPath) {
    cp.start(00, []string{"a"}, nil)
    cp.finish(01000)
    cp.start(11000, []string{"b"}, []string{"a"})
    cp.finish(12000)
    cp.start(23000, []string{"c"}, []string{"b"})
    cp.finish(24000)
   },
   want:     []string{"c", "b", "a"},
   wantTime: 3000,
  },
  {
   name: "diamond",
   //  a
   //  |\
   //  b c
   //  |/
   //  d
   msgs: func(cp *testCriticalPath) {
    cp.start(00, []string{"a"}, nil)
    cp.finish(01000)
    cp.start(11000, []string{"b"}, []string{"a"})
    cp.start(21000, []string{"c"}, []string{"a"})
    cp.finish(12000)
    cp.finish(23000)
    cp.start(33000, []string{"d"}, []string{"b", "c"})
    cp.finish(34000)
   },
   want:     []string{"d", "c", "a"},
   wantTime: 4000,
  },
  {
   name: "multiple",
   //  a d
   //  | |
   //  b e
   //  |
   //  c
   msgs: func(cp *testCriticalPath) {
    cp.start(00, []string{"a"}, nil)
    cp.start(30, []string{"d"}, nil)
    cp.finish(01000)
    cp.finish(31000)
    cp.start(11000, []string{"b"}, []string{"a"})
    cp.start(41000, []string{"e"}, []string{"d"})
    cp.finish(12000)
    cp.start(22000, []string{"c"}, []string{"b"})
    cp.finish(23000)
    cp.finish(44000)

   },
   want:     []string{"e", "d"},
   wantTime: 4000,
  },
 }
 for _, tt := range tests {
  t.Run(tt.name, func(t *testing.T) {
   cp := &testCriticalPath{
    CriticalPath: NewCriticalPath(),
    actions:      make(map[int]*Action),
   }

   tt.msgs(cp)

   criticalPath, _, _ := cp.CriticalPath.criticalPath()

   var descs []string
   for _, x := range criticalPath {
    descs = append(descs, x.action.Description)
   }

   if !reflect.DeepEqual(descs, tt.want) {
    t.Errorf("criticalPath.criticalPath() = %v, want %v", descs, tt.want)
   }

   var gotTime time.Duration
   if len(criticalPath) > 0 {
    gotTime = criticalPath[0].cumulativeDuration
   }
   if gotTime != tt.wantTime {
    t.Errorf("cumulativeDuration[0].cumulativeDuration = %v, want %v", gotTime, tt.wantTime)
   }
  })
 }
}

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