import Testing @testable import MediaKit @Suite("Auflösung einstufen") struct VideoResolutionTests { // MARK: - Nach der Breite @Test("Die üblichen Breiten") func commonWidths() { #expect(VideoResolution(width: 7_680, height: 4_320) == .uhd8K) #expect(VideoResolution(width: 3_840, height: 2_160) == .uhd4K) #expect(VideoResolution(width: 4_096, height: 2_160) == .uhd4K) #expect(VideoResolution(width: 2_560, height: 1_440) == .qhd) #expect(VideoResolution(width: 1_920, height: 1_080) == .fullHD) #expect(VideoResolution(width: 1_280, height: 720) == .hd) #expect(VideoResolution(width: 720, height: 576) == .sd) } /// Der Fall, wegen dem die Breite zuerst kommt: ein Kinofilm in 2,39:1 hat /// 804 Zeilen. Nach der Höhe wäre das „HD" — und das stand bisher an /// ausgerechnet den größten Filmen. @Test("Breitwand bleibt Full HD, nicht HD") func letterboxedStaysFullHD() { #expect(VideoResolution(width: 1_920, height: 804) == .fullHD) #expect(VideoResolution(width: 1_920, height: 800) == .fullHD) } @Test("Breitwandiges 4K bleibt 4K") func letterboxed4K() { #expect(VideoResolution(width: 3_840, height: 1_608) == .uhd4K) #expect(VideoResolution(width: 3_840, height: 1_392) == .uhd4K) } // MARK: - Nach der Höhe, wenn es die Breite nicht gibt @Test("Ohne Breite entscheidet die Höhe") func fallsBackToHeight() { #expect(VideoResolution(width: nil, height: 2_160) == .uhd4K) #expect(VideoResolution(width: nil, height: 1_080) == .fullHD) #expect(VideoResolution(width: nil, height: 720) == .hd) #expect(VideoResolution(width: nil, height: 480) == .sd) #expect(VideoResolution(width: 0, height: 1_080) == .fullHD) } // MARK: - Nach dem Namen des Servers @Test("Was Plex hinschreibt") func plexLabels() { #expect(VideoResolution(width: nil, height: nil, serverLabel: "4k") == .uhd4K) #expect(VideoResolution(width: nil, height: nil, serverLabel: "1080") == .fullHD) #expect(VideoResolution(width: nil, height: nil, serverLabel: "720") == .hd) #expect(VideoResolution(width: nil, height: nil, serverLabel: "sd") == .sd) #expect(VideoResolution(width: nil, height: nil, serverLabel: "576") == .sd) #expect(VideoResolution(width: nil, height: nil, serverLabel: "4K") == .uhd4K) } @Test("Zeilensprung wird als Zahl gelesen") func interlacedLabel() { #expect(VideoResolution(width: nil, height: nil, serverLabel: "1080i") == .fullHD) } @Test("Ohne jede Angabe keine erfundene Stufe") func nothingIsNothing() { #expect(VideoResolution(width: nil, height: nil) == nil) #expect(VideoResolution(width: nil, height: nil, serverLabel: "") == nil) #expect(VideoResolution(width: nil, height: nil, serverLabel: "irgendwas") == nil) } // MARK: - Die Namen @Test("Die Namen, die dastehen sollen") func names() { #expect(VideoResolution.uhd4K.name == "4K") #expect(VideoResolution.fullHD.name == "Full HD") #expect(VideoResolution.hd.name == "HD") #expect(VideoResolution.sd.name == "SD") #expect(VideoResolution.fullHD.technicalName == "1080p") } /// Gebraucht für „größer als 4K" in Filtern. @Test("Die Stufen lassen sich vergleichen") func ordered() { #expect(VideoResolution.sd < .hd) #expect(VideoResolution.fullHD < .uhd4K) #expect(VideoResolution.uhd8K > .uhd4K) } // MARK: - An der Fassung @Test("Die Fassung sagt Full HD statt 1080") func versionSpeaksPlainly() { let fassung = MediaVersion( id: "1", videoResolution: "1080", width: 1_920, height: 804 ) #expect(fassung.resolutionLabel == "Full HD") #expect(fassung.qualityLabel.hasPrefix("Full HD")) } /// Ohne Zahlen bleibt die Angabe des Servers die einzige Quelle — sie darf /// dann nicht verlorengehen. @Test("Auch ohne Maße kommt ein Name heraus") func labelWithoutNumbers() { #expect(MediaVersion(id: "1", videoResolution: "4k").resolutionLabel == "4K") #expect(MediaVersion(id: "1", videoResolution: "4k").pixelHeight == 2_160) } }