-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgap_test.go
More file actions
120 lines (98 loc) · 3.21 KB
/
gap_test.go
File metadata and controls
120 lines (98 loc) · 3.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
// SPDX-License-Identifier: Apache-2.0
// Copyright Contributors to the OpenTimelineIO project
package gotio
import (
"encoding/json"
"testing"
"github.com/Avalanche-io/gotio/opentime"
)
func TestGapAvailableRange(t *testing.T) {
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
gap := NewGap("gap", &sr, nil, nil, nil, nil)
ar, err := gap.AvailableRange()
if err != nil {
t.Fatalf("AvailableRange error: %v", err)
}
if ar.Duration().Value() != 48 {
t.Errorf("AvailableRange Duration = %v, want 48", ar.Duration().Value())
}
}
func TestGapSchema(t *testing.T) {
gap := NewGapWithDuration(opentime.NewRationalTime(24, 24))
if gap.SchemaName() != "Gap" {
t.Errorf("SchemaName = %s, want Gap", gap.SchemaName())
}
if gap.SchemaVersion() != 1 {
t.Errorf("SchemaVersion = %d, want 1", gap.SchemaVersion())
}
}
func TestGapClone(t *testing.T) {
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(36, 24))
gap := NewGap("test_gap", &sr, AnyDictionary{"key": "value"}, nil, nil, nil)
clone := gap.Clone().(*Gap)
if clone.Name() != "test_gap" {
t.Errorf("Clone name = %s, want test_gap", clone.Name())
}
dur, _ := clone.Duration()
if dur.Value() != 36 {
t.Errorf("Clone duration = %v, want 36", dur.Value())
}
}
func TestGapIsEquivalentTo(t *testing.T) {
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(24, 24))
g1 := NewGap("gap", &sr, nil, nil, nil, nil)
g2 := NewGap("gap", &sr, nil, nil, nil, nil)
sr2 := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
g3 := NewGap("different", &sr2, nil, nil, nil, nil)
if !g1.IsEquivalentTo(g2) {
t.Error("Identical gaps should be equivalent")
}
if g1.IsEquivalentTo(g3) {
t.Error("Different gaps should not be equivalent")
}
// Test with non-Gap
clip := NewClip("clip", nil, nil, nil, nil, nil, "", nil)
if g1.IsEquivalentTo(clip) {
t.Error("Gap should not be equivalent to Clip")
}
}
func TestGapVisibility(t *testing.T) {
gap := NewGapWithDuration(opentime.NewRationalTime(24, 24))
if !gap.Visible() {
t.Error("Gap.Visible() should be true")
}
if gap.Overlapping() {
t.Error("Gap.Overlapping() should be false")
}
}
func TestGapJSON(t *testing.T) {
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 24), opentime.NewRationalTime(48, 24))
gap := NewGap("test_gap", &sr, AnyDictionary{"note": "empty space"}, nil, nil, nil)
data, err := json.Marshal(gap)
if err != nil {
t.Fatalf("Marshal error: %v", err)
}
gap2 := &Gap{}
if err := json.Unmarshal(data, gap2); err != nil {
t.Fatalf("Unmarshal error: %v", err)
}
if gap2.Name() != "test_gap" {
t.Errorf("Name mismatch: got %s", gap2.Name())
}
dur, _ := gap2.Duration()
if dur.Value() != 48 {
t.Errorf("Duration mismatch: got %v", dur.Value())
}
}
func TestGapDuration(t *testing.T) {
// Test with source range
sr := opentime.NewTimeRange(opentime.NewRationalTime(0, 30), opentime.NewRationalTime(60, 30))
gap := NewGap("", &sr, nil, nil, nil, nil)
dur, err := gap.Duration()
if err != nil {
t.Fatalf("Duration error: %v", err)
}
if dur.Value() != 60 || dur.Rate() != 30 {
t.Errorf("Duration = %v, want 60@30fps", dur)
}
}